Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2387
Databinding to the selected row
posted

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

Parents
  • 469350
    Suggested Answer
    Offline posted

    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.

     

Reply Children