|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagridview problem Help NeededDataGridView 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. manish_sapkal1***@yahoo.co.in 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscurrencymanagerclasstopic.asp I hope this helps, Cor <sapkal.man***@gmail.com> schreef in bericht Show quoteHide quote news:1146813610.201405.212060@u72g2000cwu.googlegroups.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.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. > manish_sapkal1***@yahoo.co.in >
Sql Code generation tools
Simple questions about interfaces copying records Do nothing but wait loop.. Internationalisation Project VB.net 2005 RESX HttpWebRequest - Timeout For Each Loop Not Working Declaration Expected how to prevent the controls in a form and form itself to scroll? Reference count? |
|||||||||||||||||||||||