David Svedarsky
asked on
How to maintain row position in datagridview when cells are edited
Using a bound datagridview.
I need sample code for a datagridview to maintain row position after editing column cells.
After filling about 20 rows with data, the datagridview moves up several rows when a cell is clicked or edited.
I need sample code for a datagridview to maintain row position after editing column cells.
After filling about 20 rows with data, the datagridview moves up several rows when a cell is clicked or edited.
Are you using a windows data grid or a web datagrid?
ASKER
I am using a windows application.
Dave,
I don't understand what your code is doing, and what you need it to do. You could keep track of the current cell address, and reset it back:
Me.DataGridView1.CurrentCe ll = Me.DataGridView1(oldColumn Index, oldRowIndex)
Bob
I don't understand what your code is doing, and what you need it to do. You could keep track of the current cell address, and reset it back:
Me.DataGridView1.CurrentCe
Bob
ASKER
Bob,
Here is the code below in form_load that is causing the problem.
There are several self calculating columns, that when edited causes the datagridview to cycle or change row position (several rows)
Ay ideas where I could move the code...
'Compute(Unit Price)
Dim dc As New DataColumn
dc.Expression = "(UnitPrice*Markup)+Credit +Labor"
dc.ReadOnly = True
dc.ColumnName = "UPGRADE_PRICE"
dc.DataType = System.Type.GetType("Syste m.Decimal" )
MonarchSQLDataSet.Tables(" tblUpgrade sDetail"). Columns.Ad d(dc)
'Compute(Extension)
dc = New DataColumn()
dc = New DataColumn()
dc.Expression = "(UPGRADE_PRICE*Quantity)"
dc.ReadOnly = True
dc.ColumnName = "EXT"
dc.DataType = System.Type.GetType("Syste m.Decimal" )
MonarchSQLDataSet.Tables(" tblUpgrade sDetail"). Columns.Ad d(dc)
' Old SubTotal before adding Sales Tax.
dc = New DataColumn("SalesTax", System.Type.GetType("Syste m.Decimal" ), "(Sum(Child.EXT) + IsNull(Shipping,0)) * IsNull(TaxRate/100,0)")
dc.ReadOnly = True
MonarchSQLDataSet.Tables(" tblUpgrade s").Column s.Add(dc)
txtSalesTax.DataBindings.A dd(New Binding("Text", TblUpgradesBindingSource, "SalesTax", True))
txtSalesTax.DataBindings(" Text").For matString = "C"
'Compute SubTotal Sum(Child.EXT) * (1 + IsNull(TAX/100,0))
dc = New DataColumn("ST", System.Type.GetType("Syste m.Decimal" ), "Sum(Child.EXT)")
dc.ReadOnly = True
MonarchSQLDataSet.Tables(" tblUpgrade s").Column s.Add(dc)
SubTotalTextBox.DataBindin gs.Add(New Binding("Text", TblUpgradesBindingSource, "ST", True))
SubTotalTextBox.DataBindin gs("Text") .FormatStr ing = "C"
'Compute Total
dc = New DataColumn("TOT", System.Type.GetType("Syste m.Decimal" ), "ST+isnull(Shipping,0)+isn ull(SalesT ax,0)")
dc.ReadOnly = True
MonarchSQLDataSet.Tables(" tblUpgrade s").Column s.Add(dc)
TotalTextBox.DataBindings. Add(New Binding("Text", TblUpgradesBindingSource, "TOT", True))
TotalTextBox.DataBindings( "Text").Fo rmatString = "C"
Here is the code below in form_load that is causing the problem.
There are several self calculating columns, that when edited causes the datagridview to cycle or change row position (several rows)
Ay ideas where I could move the code...
'Compute(Unit Price)
Dim dc As New DataColumn
dc.Expression = "(UnitPrice*Markup)+Credit
dc.ReadOnly = True
dc.ColumnName = "UPGRADE_PRICE"
dc.DataType = System.Type.GetType("Syste
MonarchSQLDataSet.Tables("
'Compute(Extension)
dc = New DataColumn()
dc = New DataColumn()
dc.Expression = "(UPGRADE_PRICE*Quantity)"
dc.ReadOnly = True
dc.ColumnName = "EXT"
dc.DataType = System.Type.GetType("Syste
MonarchSQLDataSet.Tables("
' Old SubTotal before adding Sales Tax.
dc = New DataColumn("SalesTax", System.Type.GetType("Syste
dc.ReadOnly = True
MonarchSQLDataSet.Tables("
txtSalesTax.DataBindings.A
txtSalesTax.DataBindings("
'Compute SubTotal Sum(Child.EXT) * (1 + IsNull(TAX/100,0))
dc = New DataColumn("ST", System.Type.GetType("Syste
dc.ReadOnly = True
MonarchSQLDataSet.Tables("
SubTotalTextBox.DataBindin
SubTotalTextBox.DataBindin
'Compute Total
dc = New DataColumn("TOT", System.Type.GetType("Syste
dc.ReadOnly = True
MonarchSQLDataSet.Tables("
TotalTextBox.DataBindings.
TotalTextBox.DataBindings(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bob,
I tried the code example with no luck in Form_Load and MyGrid_CellEndEdit.
It looks like I am going to have to try and figure out how to take the column calculations out of Form_Load and move them to a Button_Click event and only load the data in Form_Load.
I assume that this is beyond the scope of EE.
I tried the code example with no luck in Form_Load and MyGrid_CellEndEdit.
It looks like I am going to have to try and figure out how to take the column calculations out of Form_Load and move them to a Button_Click event and only load the data in Form_Load.
I assume that this is beyond the scope of EE.
I have seen some wild and strange things over the years, so I don't know what EE's "scope" is really limited to, other than the membership guidelines (like doing homework, flaming, etc.).
It is difficult to say with any certainty what the "best" course of action is without understanding your process better.
Bob
It is difficult to say with any certainty what the "best" course of action is without understanding your process better.
Bob