I bound my grid to data table.I enter value in column 1 and key 'Enter' event I want read this value populate columns 2 and 3 based on value in column 1? But grid.ActiveRow.Cells(0).Value is null
What event are you using?
The Value property of the cell comes from the data source underlying that cell. So the Value of a cell cannot be updated on every keystroke. It is usually updated once the user leaves the cell.
You can either force the cell to update by calling the Update method on the row, or you could use the Text property of the cell, which will reflect what the user typed.
I'm using KeyDown event and trying to find cell value after pressing Enter key.
This is snippet of my code.
Private Sub grdRapidCash_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdRapidCash.KeyDown Try If grdRapidCash.ActiveCell.Column.Index = 0 Then If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then mstrValue = grdRapidCash.Rows(0).Cells(0).Text mstrValue = grdRapidCash.ActiveCell.Text End If End If
Catch exp As Exception
End Try
End Sub
I tried to put before read
grdRapidCash.Update()grdRapidCash.UpdateData()grdRapidCash.Refresh()grdRapidCash.ActiveRow.Update()grdRapidCash.ActiveCell.Refresh()
mstrValue in both cases equal empty string
I tried this out using the same code you have here and it works just fine for me. The Text property on the cell is returning the actual text on the screen and the Value property returns the value from the underlying data source, which has not yet been changed.
What version of the controls are you using? I tested with v10.3 with the latest service release. So maybe this was a bug in the version you have.
I had problem with version v.8.3....
But it is working in version v.9.1., we are not using version v.10.3.
I have other question.
How to set focus in first cell of new row after I press Enter Key
If grdRapidCash.ActiveCell.Column.Index = 4 Then If e.KeyCode = Keys.Enter Then grdRapidCash.DisplayLayout.Bands(0).AddNew() End IfEnd If
I tried:1.grdRapidCash.ActiveCell = grdRapidCash.ActiveRow.Cells(0)grdRapidCash.PerformAction(UltraGridAction.EnterEditMode, False, False)
2.grdRapidCash.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.NextCellByTab, False, False)
Hi,
This will be tricky to do while the grid is in the middle of processing a key. You will probably have problems with timing if you use KeyDown. I would use KeyUp, instead.
Private Sub UltraGrid1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles UltraGrid1.KeyUp If Me.UltraGrid1.ActiveCell.Column.Index = 4 Then If e.KeyCode = Keys.Enter Then Dim newRow As UltraGridRow = Me.UltraGrid1.DisplayLayout.Bands(0).AddNew() newRow.Cells(0).Activate() Me.UltraGrid1.PerformAction(UltraGridAction.EnterEditMode) End If End If End Sub
By the way... it's generally a bad idea to identify a column by Index, like you are doing in your 'if' statement here. The Index of a column will change if the columns are moved, either in code or by the user. You should probably use the column's Key, instead.
Thanks.
It works