In order to fill-in a WinGrid I do the following
source = (UltraDataSource) myGrid.DataSourcemyObjCollection = GetMyObjCollection()Dim row(source.Band.Columns.Count - 1) As Object
Foreach myObj in myObjCollection i = 0 row(i++) = myObj.myProperty1 row(i++) = myObj.myProperty2 ... Dim uRow = source.Rows.Add(False, row, False) uRow.Tag = myObj Next myObj
Now we have a lot of rows in the grid filled with data of myObjCollection. So, once some of my rows are selected by user, I want to recuperate the BO from the rows tags,
I use:
Foreach row in myGrid.Selected.Rows row.Tag = Nothing ' WHY? How to recuperate the DataSource Row Tag value?
PS. Actually I do it like this:
For Each row In grdResult.Selected.Rows Dim mySourceRow = TryCast(row.ListObject, UltraDataRow) If mySourceRow IsNot Nothing Then Dim myObj = TryCast(mySourceRow.Tag, MyObjClass) If myObj IsNot Nothing Then myObj.Selected = True End If End If Next row
But perhaps there is a more elegant way to do it...
Hi,
I'm having a hard time understanding what this code is doing. It doesn't make a lot of sense. You seem to be creating an array of rows, but you are using the number of Columns as the count of the array instead of the number of rows in the data source. I'm also not really sure what the point of the array is, since you are filling it with properties of your data source, but then you are not doing anything else with it.
You have a counter here (i), which is incremented, but not defined or used anywhere else. Your 'next' statement doesn't match up to your 'Foreach'. And I don't know what 'v' is so I don't understand what you are assigning to the row's Tag.
It looks like maybe you are assigning 'v', whatever it is, so the Tag of the row in the UltraDataSource, and then you are reading the tag of the UltraDataSource row, so it seems like that should work.
But the code you posted here is so incomplete and jumbled, that I really can't make much out of it.
I updated the initial post.
The situation is classical. I initialize the grid's columns (say I have 10 columns).Then I have my collection of objects, and I fill-in the grid's DataSource ( i is the current column index)Finally, in order do not have just distinct properties of MyObject in a row, but to have a reference to the myObject itself, I use the row's Tag to set the object itself.Finally, if I have, say, 12 objects, I will have 12 rows and 12 tags with that objects. Each Object will contain displayed 10 of its properties in every of that 12 rows.Finally, the user selects only 3 of 12 objects, so I need to identify what object of 12 was selected.Grid -> objects collectionRow -> objectCell -> object's property.