Re: DataGrid's Cell with DataGridTextBox's Change event
Originally posted by parminder Problem 1:
How to prevent the user to add a new row in DataGrid and allow him to modify existing rows ?
Bind it to a dataview that its allownew is set to false.
And for the second problem. I wouldnt catch the textbox change event of datagrid, instead i will add this line to the code and let alone that textchange event.
VB Code:
datColumn = New DataColumn("Amount", System.Type.GetType("System.Decimal"))
[b]datColumn.Expression = "Rate * Qty"[/b]
myDataTable.Columns.Add(datColumn)
Last edited by Lunatic3; Sep 2nd, 2003 at 12:44 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
And the reason your code does not work is that while you are changing the text in the datagrid text, the underlying datasource is not updated yet and its value is still the same untill you move away from that column. So using your code you should move to another column, then back to this column and now if you change it. the 'Amount' column will be updated by the previous 'Qty'.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
your alternative solution is good. I also found the other alternative solution. I changed the code of QtyTextBoxChanged procedure as follows (but still your code is good)
VB Code:
Private Sub QtyTextBoxChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ftb As FormattableTextBoxColumn
ftb = sender
If Not (OldRow = Me.DataGrid1.CurrentCell.RowNumber And OldCol = Me.DataGrid1.CurrentCell.ColumnNumber) Then
When I design KeyPress or KeyDown events of FormattedTextBox, the event is not fired when I press "Enter" (and some special keys like leftarrow,rightarrow). Other Alfa and Numeric keys works fine. How to handle this problem.
I want, when user press Enter, Rightside cell in same row should make active (or any specific)