how to get selected object in bindinglist in datagridview

996 views
Skip to first unread message

Sebastian

unread,
Dec 20, 2008, 9:59:00 AM12/20/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hello everyone,

I have created a BindingList<Primitive> where Primitive is a class
which I created myself.
I am able to bind the BindingList to a DataGridView and it shows the
information I want to see.

I can select rows using SelectionMode with FullRowSelect. Is it
possible to retrieve the selected Primitive from the dataGridView (and
not just the values of the grid cells)?

Many thanks, Sebastian

Chitresh

unread,
Jan 5, 2009, 9:44:04 AM1/5/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi Sebastian,
Try the following code( C# ) :

Primitive selectedPrimitive = (Primitive)dataGridView1.Rows
[dataGridView1.CurrentCell.RowIndex].DataBoundItem;

I guess that should do it.
Reply all
Reply to author
Forward
0 new messages