Home Forums WinForms controls Xceed Grid for WinForms Get the value of a Cell ? Reply To: Get the value of a Cell ?

User (Old forums)
Member
Post count: 23064

The previous reply showed you how to get the value of a cell using c# – here’s how I do it using VB.NET (Yes, VB.NET allows you to stack a ton of functions onto the same line, identical to C# but I’m “old school” and prefer looking at code that’s easy to read…so you’ll have to excuse my older way of writing!)

FYI – this will work with bound or unbound…makes no difference.

‘ This first function sets up the Grid to handle a couple of events…in this case, a single and a double-click

Private Sub InitGrid()
‘ Right-Click event handler
AddHandler colTemplate_RunNumber.MouseDown, AddressOf runExp_Click
AddHandler colTemplate_RunName.MouseDown, AddressOf runExp_Click

‘ Double-Click event handler
AddHandler colTemplate_RunNumber.DoubleClick, AddressOf runExp_DoubleClick
AddHandler colTemplate_RunName.DoubleClick, AddressOf runExp_DoubleClick
End Sub

‘ Here’s the Single-Click routine. In my ap, I have a context-menu that pops up so I’m only trapping the right-click here.
Private Sub runExp_Click(ByVal sender As Object, ByVal e As System.windows.Forms.MouseEventArgs)
Select Case e.Button
Case MouseButtons.Right
Dim reCellRow As CellRow
Dim reGridRow As Xceed.Grid.DataRow
reCellRow = (CType(sender, Cell).ParentRow)

‘ Select the row they clicked on…
grdRunExp.SelectedRows.Clear()
grdRunExp.SelectedRows.Add(reCellRow)
grdRunExp.CurrentRow = reCellRow

‘ Demo getting s value from a Cell on a single-click
Dim sClient As String
Dim sRunNumber as String

‘ Here’s a value in that Row under the “RunNumber” column
sRunNumber = CType(reCellRow.Cells(“RunNumber”).Value, String)

‘ Here’s another value in that same Row, under the “ClientName” column
sClient = CType(reCellRow.Cells(“ClientName”).Value, String)

Case Else
End Select
End Sub

‘ More of the same, but demos the trapping of the double-click.
Private Sub runExp_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim reCellRow As CellRow
Dim sClient As String
Dim sRunNumber as String

‘ This the row of the cell that was clicked on
reCellRow = (CType(sender, Cell).ParentRow)

‘ Here’s a value in that Row under the “RunNumber” column
sRunNumber = CType(reCellRow.Cells(“RunNumber”).Value, String)

‘ Here’s another value in that same Row, under the “ClientName” column
sClient = CType(reCellRow.Cells(“ClientName”).Value, String)
End Sub

Hope this helps!

-LK

Imported from legacy forums. Posted by Curtis (had 4413 views)