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
2700
UltraGrid with multiple checkboxes in each cell
posted

I have a need to create an UltraGrid where the columns are days of the week but each column contains 3 checkboxes for breakfast, lunch and dinner.  

So each row would have the name of the person, followed by 7 columns each of which would contain the 3 checkboxes.  I had though of using the UltraControlContainer to contain a user control which has 3 check boxes but I'm not sure if this would be the best way of achieving this?

Could I possible use multiple bands in the UltraGrid to effectively have 3 separate columns beeath each day column.  That is the first row has 8 columns, one for the name and 1 for each day of the week whereas riows 2 to n would have 22 columns, the first name column and then 3 per day?

  • 469350
    Verified Answer
    Offline posted

    Hi Chris, 

    There are a few different approached you could take here. Which approach you take may depend on the requirements for your data source - assuming you have any. 

    If your data source doesn't matter, or is flexible, then the simplest approach would be to simple have a column for each day and meal combination. So you would just have a data source with 21 boolean columns like:

    "Monday Breakfast"

    "Monday Lunch"

    "Monday Dinner"

    "Tuesday Breakfast"

    "Tuesday Lunch"

    "Tuesday Dinner"

    Of course, you wouldn't want labels like that in the grid, because it would be hard to read. So you could handle that by using Groups and maybe making the headers display text vertically to save space. 

    I put together a quick sample of this approach and I have attached it here. Vertical headers seems kinda big to me, so I went with Horizontal90Degreesand I think that looks better. Another alternative would be to use "B", "L", and "D" as the captions. 

    If you really want all of the checkboxes in a single cell, then you could do that, but it would be trickier. for one thing, you would need to have a single field in your data source that can store 3 different checkboxes values. Maybe use an array of bools or a custom class. This would mean implementing property change infrastructure on that class and on the collection that contains them. And you would need either a UserControl with an UltraControlContainerEditor or else a CreationFiilter. Basically, this approach would require a lot more work and delving into the extensibility features of the grid. It would not be terrible, but it's a lot more complicated than the approach I took here. 

    Multiple Checkboxes using Groups.zip