getting item id from datagridviewgetting item id from datagridview
Old forum URL: forums.lhotka.net/forums/t/155.aspx
dean posted on Saturday, May 20, 2006
in his window forms example, when using a datagridview to display his collections, rocky has a non visible column (width=5 for some reason) hold his item key. This he accesses with:
resourceid = CInt(Me.ResourcesDataGridView.SelectedRows(0).Cells(0).Value)
This is similar to the strategy used with his datalistview control from csla 1.0/1.5 days.
One of the problems with this is you can't let the user change column widths.
What about using:
ResourcesDataGridView.CurrentRow.DataBoundItem.ToString
since we override each objects tostring with our key value this seems to work. Additionally you can get any property value by casting it to your object type. For instance in project edit, resourcesdatagridview, project resource item:
RoleID = ctype(ResourcesDataGridView.CurrentRow.DataBoundItem,ProjectResource).Role
Anyone see any problems with this?
Dean
xal replied on Saturday, May 20, 2006
It's always best to use your currency manager / binding source.
I think it's:
yourBindingSource.Current
(I don't have access to the code now, and since this is coded in my base class it's not something i do too often...)
You'll have to cast it to whatever your item is...
DirectCast(yourBindingSource.Current, ObjectType).ObjectId
Make sure you check for nulls!!
Andrés
Copyright (c) Marimer LLC