Results 1 to 3 of 3

Thread: double click on datagrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Wink double click on datagrid

    Hi there,
    I m a beginner in VB.Net.

    I have created a form with a datagrid. What i would like to do is double click on a row within the datagrid to open another form displaying the contents of that record to the textbox.

    What is the coding in the datagrid_double click even ??

    any help or examples appreciated

    Thanks,
    viv

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    this one maybe could help you
    VB Code:
    1. Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
    2.         TextBox1.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
    3.     End Sub
    4.  
    5.     Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
    6.         DataGrid1.Select(DataGrid1.CurrentCell.RowNumber)
    7.     End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Wink

    Mar_zim,

    thank you very much for your quick reply.

    I am facing 2 problems now.

    1. if I selected <ALL> from the cboCustomer and click search button, all sorted records display. BUT when I double click on the first record on that grid, the records is not fill into the textbox in Form1. This only happen in first record on that grid , other records are working fine.

    2. if I selected any alphabet instead of <ALL> from the cboCustomer and click search button, the records display is ok. BUT when I double click on the specific record on that grid, is not the selected record will fill into the textbox in Form1.

    Here¡¯s the code :
    In Form1
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim Search As New frmCustSearch
    Search.DataSource = DataSet11
    Search.DataMember = DataSet11.Customers.TableName
    Search.CM = Me.BindingContext(DataSet11, DataSet11.Customers.TableName)
    Search.ShowDialog()

    End Sub

    In Form2(frnCustSearch)
    Private Sub frmCustSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    dvCustomer = New DataView(Me.DataSet11.Tables("Customers"), "CustLName like '%'", "", DataViewRowState.OriginalRows)
    cboCustomer.Items.AddRange(New Object() {"<ALL>", "A", "B", "C", "D", "E", "F", "G", _
    "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"})
    cboCustomer.Text = "<ALL>"

    Me.SqlDataAdapter1.Fill(Me.DataSet11.Customers)

    End Sub

    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick

    Dim CM1 As CurrencyManager = CType(Me.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember), CurrencyManager)
    If CM1.Position > -1 Then
    Me._CM.Position = CM1.Position
    Me.DialogResult = DialogResult.OK
    End If
    End Sub

    Thank again,
    viv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width