1 Previous Next 

DataGrid: Detect changed row


Datagrid dectect changed row

This sample shows how to use the currencymanager with a datagrid.

This sample needs only a form with two long datagrids on it the one above the other. Private Sub Form1_Load(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet
        Dim dt As New DataTable
        ds.Tables.Add(dt)
        dt.Columns.Add("Name")
        dt.Columns.Add("Place")
        dt.LoadDataRow(New Object() {"Cor", "Holland"}, True)
        dt.LoadDataRow(New Object() {"Ken", "Florida"}, True)
        dt.LoadDataRow(New Object() {"Jay", "New York"}, True)
        dt.LoadDataRow(New Object() {"Herfried", "Austria"}, True)
        dt.LoadDataRow(New Object() {"Armin", "Germany"}, True)
        dt.LoadDataRow(New Object() {"Terry", "UK"}, True)
        DataGrid1.DataSource = dt.DefaultView
        dt.DefaultView.AllowDelete = False
        dt.DefaultView.AllowEdit = False
        dt.DefaultView.AllowNew = False
        Dim cma As CurrencyManager = DirectCast _
        (BindingContext(dt.DefaultView), CurrencyManager)
        AddHandler cma.CurrentChanged, AddressOf rowchanging
        rowchanging(Me, Nothing)
End Sub
Public Sub rowchanging(ByVal sender As Object, _
    ByVal e As EventArgs)
        Dim dv1 As DataView = DirectCast(DataGrid1.DataSource, DataView)
        Dim dv2 As New DataView(DirectCast(DataGrid1.DataSource, DataView).Table)
        Dim cma As CurrencyManager = DirectCast(BindingContext(dv1), CurrencyManager)
        dv2.RowFilter = "Name = '" & dv1(cma.Position)("Name").ToString & "'"
        DataGrid2.DataSource = dv2
End Sub



1 Previous Next