I have a WinGrid that has two bands. It is being used as a picker control. In other words the user will see the grid and be able to pick one of the band[0] that will be used else where in the application. The dataset is home grown:
class OptionDetails { public string Name { get; set; } } class Options { public string Name { get; set; } public int DetailCount { get { return this.Details.Count; } } private BindingList<OptionDetails> Details = new BindingList<OptionDetails>(); } class CustomDataSet { BindingList<Options> optionsToPickFrom; Options selectedOption; }
I am successfully binding to the WinGrid to the CustomDataSet.optionsToPickFrom to display the list, you all helped me yesterday to get it to look like this:
The question is: How do I setup the databinding so that CustomDataSet.selectedOption will be the currently selected item, based on the screen shot, it should be the "Yes/No/Maybe" option. Of course part of the objective is to be able to set the CustomDataSet.selectedOption to an Options object initially and the WinGrid would start off with that being the selected item.
I have seen the help section titled "Change the Active Row". The issue with this of course is that I don't know which UltraGridRow is selected upon display of the WinGrid, I know what one of the UltraGridRow's is bound to: an instances of the Options class.
Now I think about it, when CustomDataSet.selectedOption is set initially, any thoughts on how to I could use conditional formatting to keep the text of the initially selected row to stay bold? I cannot modify the CustomDataSet, Options, or OptionDetails, it violates the whole concept of seperation of UI and data :)
Sam
Hi Sam,
There's a property on the row called ListObject which returns the object that the row represents in the underlying data source of the grid.
So if you know which object you want selected, what you can do is loop through the grid's Rows collection and check the ListObject of each row against the CustomDataSet.selectedOption until you find the one you want.
Mike,
Ouch! The WinGrid is already looping through the list once, the last thing that should happen is looping through it a second time, especially if it is a large list, can you say SLOW!!!!! :)
FYI: Your responce does not address my original question of data binding to the selected item. I take it the answer to my original question is "It cannot be done exclusively with data binding.", correct?
scarleton said:Ouch! The WinGrid is already looping through the list once, the last thing that should happen is looping through it a second time, especially if it is a large list, can you say SLOW!!!!! :)
I suppose one way you could handle this would be to create a Dictionary and use the grid's InitializeRow event to populate it such that the keys are your ListObjects and the value is the UltraGridRow.
scarleton said:FYI: Your responce does not address my original question of data binding to the selected item. I take it the answer to my original question is "It cannot be done exclusively with data binding.", correct?
You mean you are trying to "bind" the grid's ActiveRow to a property on your class? No, I don't beleive there is any way to do that.