Get ID of selected row

L

leodippolito

Hello,

I have an ArrayList bound to a DataGrid.

This ArrayList is a collection of MyObject's.

MyObject class has two properties:

(example)

MyObject.ID = 1;
MyObject.Name = "abc";

In this DataGrid I have a TableStyles object with 1 GridColumnStyles so
that the grid will show ONLY the Name (second property of MyObject).

When a user selects a row, I need to get the ID of Name selected in
that row (in other words, the primary key). It is not visible in the
grid, because I don't have a GridColumnStyles for it. Therefore I don't
know how to get it.

Any idea?

Leonardo
 
J

Josip Habjan

Hi,

Use CurrencyManager.

Dim cm As CurrencyManager =
CType(yourDataGrid.BindingContext(your_arraylist), CurrencyManager)

... to get selected item:
Dim selitem As MyObject = CType(cm.Current, MyObject)
Debug.Write(selitem.ID)

Regards,
Josip Habjan
URL: www.habjansoftware.com
 

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