DataGrid Question - Using a column in a selected row - Newbie

Hi,

I am trying to select a row in a DataGrid by simply clicking on the row (any column in the row) which will in turn open a new form with various controls which are binded to the original record which was selected in the DataGrid.

I have the following code which selects the whole row when clicked


  Private Sub DataGridComplaints_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridComplaints.MouseUp
        Dim pt = New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = DataGridComplaints.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            DataGridComplaints.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            DataGridComplaints.Select(hti.Row)
        End If
    End Sub


How do I use a column in the selected row to pass information into a variable which can then be used on the next form

Many thanks for any help you can give me.


Answer this question

DataGrid Question - Using a column in a selected row - Newbie

  • Marcelo Paiva

    there is a much easier way to do what you did.

    Dim CM as currencymanager = ctype(me.bindingcontext(datagrid.datasource,datagrid.datamember),currencymanager)

    datagrid.select(cm.position)

    then pass the datarowview to the form

    Dim DRV as datarowview = ctype(cm.current,datarowview)

    Dim Form as new form

    form.drv = drv 

    then in the form load event you would setup bindings

    textbox1.databindings.add(new binding("Text",drv,"ColumnName"))

    and you are all done. So when you change the values and close the form, they will be reflected in the grid.


  • DataGrid Question - Using a column in a selected row - Newbie