Datagridview problem Help Needed

S

sapkal.manish

Question : How can I find actual row position of DataTable in
DataGridView when DataTable is sorted


/ My source code like this

Private WithEvent dgvInwDet as new DataGridView
Private WithEvent DataTable as New DataTable


Private Sub frmInward_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load

'Configure DataGridView Style as Per Custome Requirement
ConfigerDataGridViewStyle()

'Create DataColumn in DataTable and DataGridView

'DataTable's Fields are
'ID, ShortCode, Name, Address, Editable
'DataGridView's Fields are
'ShortCode, Name, Address
'ID, Editable fields are hidden

CreateDataGridViewColumns()

'Index on 2 fields
InwDetTbl.DefaultView.Sort = "ShortCode ASC, Name ASC"

'Assign DataSource to DataGridView
dgvInwDet.DataSource = InwDetTbl

End Sub

Private Sub FillData()
'Fill Data in DataTable
Dim DataRow As DataRow

For iCtr = 0 to 100
DataRow = InwDetTbl.NewRow
DataRow.Item(0) = iCtr
DataRow.Item(1) = iCtr
DataRow.Item(2) = Name
DataRow.Item(3) = Address
DataRow.Item(4) = IsEditable() 'Return True or False
next

End Sub

Private Sub dgvInwDet_CellBeginEdit(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles
dgvInwDet.CellBeginEdit
Try
e.Cancel = Not IsEditable(e.RowIndex)
Catch ex As Exception
ErrorMessage()
End Try
End Sub

Priavate Function IsEditable(nRowNo as integer) as Boolen
DIm lRetVal as boolen

'If i don't sort datatable, it works perfect,
'but if i made sort on datatable how can I found actual position in
DataTable

' In this case I found wrong position in CurrencyManager
if CInt(DataTable.Row(dgvInwDet.CurrentCell.RowIndex).Item(0)) = 50
then
lRetVal = false
else
lRetVal = True
endif

Return lRetVal
end Function


If you have any Idea, Sample Code, Artical regarding above problem as
well as any information regarding DataGridView, Please send me on my
e-mail address.
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top