By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,207 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,207 IT Pros & Developers. It's quick & easy.

Datagridview problem Help Needed

P: n/a

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.DataGridViewCellCancelEventAr gs) 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.
ma***************@yahoo.co.in

May 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sapkal,

Try forever to use the defaultview of the datatable as datasource.

If you are not possible to do that, than try the currencymanager. The
manager that keeps the current possition, not the money.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

<sa***********@gmail.com> schreef in bericht
news:11**********************@u72g2000cwu.googlegr oups.com...

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.DataGridViewCellCancelEventAr gs) 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.
ma***************@yahoo.co.in

May 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.