Double Click Cell from SFDataGrid & Input into Textbox

Hi All, 

I'm extremly new to VB.NET and Sync Fusion. I've managed to get this working on a standard Datagridview within Visual Studios with the below code but unable to do the same with the syncfusion grid, which i prefer due to the filters. 

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

        Dim Part = DataGridView1.Rows(e.RowIndex).Cells(3).Value
        Dim Qty = DataGridView1.Rows(e.RowIndex).Cells(1).Value

        Dim form As New Form2
        form.TextBox1.Text = Part
        form.TextBox2.Text = Qty
        form.ShowDialog()


    End Sub

3 Replies

AA Arulraj A Syncfusion Team August 24, 2018 08:38 AM UTC

Hi Paul, 

Thanks for contacting Syncfusion support. 

You can use SfDataGrid.CellDoubleClick event to achieve your requirement. Please refer to the following code example and sample. Here we have provided the sample with the underlying data object named OrderInfo. You can cast the RowData with your underlying data object.   

Code Example: 
AddHandler Me.sfDataGrid.CellDoubleClick, AddressOf sfDataGrid_CellDoubleClick 
 
Private Sub sfDataGrid_CellDoubleClick(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs) 
                Dim form = New Form2() 
                form.textBox1.Text = (TryCast(e.DataRow.RowData, OrderInfo)).OrderID.ToString() 
                form.textBox2.Text = (TryCast(e.DataRow.RowData, OrderInfo)).CustomerID 
                form.ShowDialog() 
End Sub 



Please refer to the following UG link to get the cell value by using click events. 

 
Regards, 
Arulraj A 



PA Paul August 24, 2018 06:57 PM UTC

Thanks for your help. 

I'm now getting the below error message: Also have a put the Addhandler in the correct place on the code. 

System.NullReferenceException occurred
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=SyncFusionDataGridPopulateTxtBox
  StackTrace:
   at SyncFusionDataGridPopulateTxtBox.Form1.sfDataGrid_CellDoubleClick(Object sender, CellClickEventArgs e) in 

---------------------------- Code Here
Imports Syncfusion.Data
Imports Syncfusion.WinForms.DataGrid

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'TESTDataSet.UDEF_STOCK_BY_LOCATION_LEEDS' table. You can move, or remove it, as needed.
        Me.UDEF_STOCK_BY_LOCATION_LEEDSTableAdapter.Fill(Me.TESTDataSet.UDEF_STOCK_BY_LOCATION_LEEDS)
        AddHandler Me.SfDataGrid1.CellDoubleClick, AddressOf sfDataGrid_CellDoubleClick

    End Sub


    Private Sub sfDataGrid_CellDoubleClick(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs)
        Dim form = New Form2()
        form.TextBox1.Text = (TryCast(e.DataRow.RowData, TESTDataSet.UDEF_STOCK_BY_LOCATION_LEEDSRow)).Part_Code
        form.TextBox2.Text = (TryCast(e.DataRow.RowData, TESTDataSet.UDEF_STOCK_BY_LOCATION_LEEDSRow)).Description_1
        ' form.ShowDialog()
    End Sub


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)

    End Sub


End Class


AA Arulraj A Syncfusion Team August 27, 2018 11:05 AM UTC

Hi Paul, 

Thanks for your update. 

We suspect that the NullReferenceException may occurs due to any of the following reasons.  
  1. e.DataRow.RowData may be null.
  2. The DataSource you have used may be of type DataTable.

Here we have provided a sample project and code example to achieve your requirement if the DataSource is a DataTable. We have also included a null check to check whether the RowData is not null. 
Code Example :  
Private Sub sfDataGrid_CellDoubleClick(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs) 
       If e.DataRow IsNot Nothing AndAlso e.DataRow.RowData IsNot Nothing Then 
              Dim form = New Form2() 
              form.textBox1.Text = (TryCast(e.DataRow.RowData, DataRowView)).Row.ItemArray(0).ToString() 
              form.textBox2.Text = (TryCast(e.DataRow.RowData, DataRowView)).Row.ItemArray(1).ToString() 
              form.ShowDialog() 
       End If 
End Sub 

 
In case, the above provided solution doesn’t resolve your issue, Please provide us more information about the error. It will be helpful for us to provide an exact solution for the query. 

Arulraj A 


Loader.
Up arrow icon