detect row change

S

Sam

Hi,
In the Microsoft datagrid, how do you detect when the selected row
changes?

I've tried this:

Private WithEvents m_bindingManager As BindingManagerBase

'dgeq is my datagrid and it has a correct datasource
m_bindingManager = Me.BindingContext(dgeq.DataSource)
AddHandler m_bindingManager.PositionChanged, AddressOf RowChanged

Private Sub RowChanged(ByVal send As Object, ByVal e As
System.EventArgs) Handles m_bindingManager.PositionChanged

But it doesn't work, the change is never detected :(

Can you help,
thx
 
C

Cor Ligthert

Sam,

I was almost forgotten that I had made once a sample for that.

It needs two datagrids on a form above each other.

\\\
Private Sub Form8_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
///
I hope this helps,

Cor
 
S

Sam

Cor,

It needs two datagrids on a form above each other. -> What the hell
for ?!? Is the microsoft datagrid that crap so we can't even detect in
a easy when there is a row selection change ???
 
C

Cor Ligthert

It needs two datagrids on a form above each other. -> What the hell
for ?!? Is the microsoft datagrid that crap so we can't even detect in
a easy when there is a row selection change ???
Sam to see how the sample works, I made it that way to see it working.

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top