I have a requirement to use a dropdown checkbox list in a grid. Each cell in this column should display the concatenation of the 'name' field of the checked items in its list.
I have done this before with a good deal of tinkering--see the post "Adding Checkbox List As Dropdown From Text Editor In Grid Cell", towards the bottom.
However, now I have available the new Infragistics CheckedListSettings, and am wondering: what is considered the 'best practice' for creating and using DataSources for an UltraCombo editor control set as a checkbox list that is assigned to a grid column? What is the easiest way to use this functionality? Anything to streamline the current approach (which is onerous) would be helpful.
Thanks,
J
Hi J,
I'm not sure I understand the question. The DataSource of the list really doesn't matter all that much. You could use any DataSource you like: A DataTable, DataSet, UltraDataSource, BindingList<T>, List<T>, or any class which implements IList or IBindingList.
When choosing a DataSource for the grid, there are some performance and efficiency concerns, some of which are discussed here:
WinGrid Performance Guide
Wingrid Performance and DataSources - Infragistics Forums
But for the drop down list, there isn't as much of a concern, because it's a flat list with no child bands.
Hey Mike,
As always, thanks for the prompt replies. I'm sorry I wasn't more clear in my original post, but I'm not sure how to ask the question. I'll try and describe the situation more clearly.
Here's what I have: A list of contracts to be displayed in a grid, with certain editable fields (name, active or not, start and end dates, etc.). For each contract, there can be zero to many sources, and the requirement is to display a checkbox dropdown list to allow the user to select/unselect the funding sources on each row.
Ideally, I would love to pull a DataSet with the parent table as the Contracts and the child table as the Sources, but that will just give me child rows instead of checking the boxes in the drop down. My past solution on a similar problem was to turn off child bands and add a DataColumn of type List<T> to the DataTable that acted as the grid DataSource, then to manually check the boxes in each dropdown on the BeforeCellListDropdown grid event (I think that's what it's called). That also required me to iterate through each row's list (during InitializeRow), read the values of the checked items in the list, and concatenate those values for the string value to put in the cell itself.
I guess what I'm asking is this: given this data model, what is the ideal 'way to do it'? What I want is to be able to set the grid DataSource to a DataSet; have the parent DataTable populate the main grid; and instead of the child table creating child rows, somehow have the child table act as the DataSource for the Editor in the dropdown checkbox column--so that when the user clicks the dropdown, the correct rows are checked. Once I type it all out, it sounds like I'm asking for quite a bit.
I'm going to go ahead and try using separate, unrelated DataTables for Contracts and Sources, use InitializeRow to set the cell value for the text, and on BeforeCellListDropDown, query a DataView from the Sources DataTable (using the contract ID from the current row) and set that DataView as the DataSource for the dropdown. I'll let you know how it goes.
Mike,
I am using a DataTable (with columns "ID" and "Name") to bind to the ComboBox's DataSource, and I add a "Checked" column during InitializeLayout for the checkboxes. I set the ComboBox's DisplayMember to "Name" and the ValueMember to "ID"; I also set CheckStateMember to "Checked" and EditorValueSource to CheckedItems.
I started with a List<int> of the IDs that need to be checked as the value for the grid cell in the column that has the ComboBox as its EditorControl. I verified that the Lists are being properly populated, but none of the cells show anything even when there are items in the Lists. Also, when I drop down the ComboBox and show the grid, the Checked column is all in an indeterminate state, they did not check and uncheck as they should.
So I added a DataFilter to the Checked column in the ComboBox's InitializeLayout, using "Checked" and "Unchecked" as the actual values to check against (and return) in the implementation of Convert, as at some point during debugging I had seen those values being passed around (I realized "Y" and "N" weren't working). This led to the checkboxes all being unchecked when the grid is shown, also not correct. I have also tried using a string of ID's, separated by commas, instead of the List<int> for the cell value, but it also does not work (with and without DataFilter on Checked column).
Finally, when I click on a checkbox cell in the dropdown grid, nothing happens until the third click, when the correct name shows up in the parent table's cell (even though the checkbox never checks)--but then that disappears when click out of the row.
Any more pointers?
Thanks again,J
I tested this out and it looks like the Value of the combo returns a List<object>. So the column in the grid has to be using that type.
I'm attaching my sample here so you can take a look.
Thanks for that sample, I just played with it some to make it look more like what I'm doing to see if I could get it to work, and for some reason, I can't even get the column for the dropdown list to show up.
Will you please see attached zip file for my version of your sample and have a look? I am certainly having a stupid hard time with this.
Thanks,J
It's not showing up because you FUNDING_SOURCES column is a List<T> , so the BindingManager interprets it as a child band instead of as a normal column.
It worked for me, because UltraDataSource works differently and allows me to define the column as a column with a DataType of List<T>. But since you are using an object with properties, the BindingManager doesn't know that you want to treat the child list as a column and not a child band.
There are a couple of ways you could handle this. One would be to change the type on the FUNDING_SOURCES column object. You could still store a List in it, but since it will be a single object, the BindingManager will treat it like a column.
Another option would be to add an Unbound Column to the grid whose DataType is List<object>, and then you could populate that column in the InitializeRow event - copying the data from the child band into the unbound column. You would then have to reverse this process in the BeforeRowUpdate event to propagate the user's changes back to the data source.
Sorry it's been so long since I've been able to come back to this, but I was pulled onto other projects. I am briefly experimenting with creating an UltraDataSource in the code from the data, and using it like you did, but I was hoping you'd expand some on part of your previous post:
Infragistics - Mike Saltzman said:There are a couple of ways you could handle this. One would be to change the type on the FUNDING_SOURCES column object. You could still store a List in it, but since it will be a single object, the BindingManager will treat it like a column.
So do you mean set Band.ColumnsCollection["FUNDING_SOURCES"]. Datatype = object? And then still put the List in that column, but maybe cast it to object first? I'm a but unclear how to proceed with this suggestion.
Thanks again for your time,
Awesome, works! Sorry that took so long.
Thanks again for all the help. Only thing I would say is that your last reply doesn't show up in the thread when I access the thread from Forums --> My discussions --> then the thread.
Your reply *does* show up when I click on the link to it from my e-mail notification. The difference seems to be that your latest reply has the thread located in community.infragistics.com/forums, whereas when I access the thread through My Discussions, it takes me to forums.infragistics.com; this may cause confusion for other users.
Peace,
I took a quick look.I think the problem is that you are setting the Column Style to DropDownList. This style requires that the value of the cell match an item on the list and this case that will never happen. So if I turn off DropDownList style, it seems to work okay, at least in the first sample (DropdownCheckboxTestColumnMethod).
I got it to work in the sense that the dropdown properly checks the right rows and the cell itself has the right text; however, I get a data validation error when I try to leave the cell.
I also tried doing the other way you suggested, converting the data over from the cell with the List<int> to the unbound List<object> cell in InitializeRow, then pulling the data back out in BeforeRowUpdate. Same error. I've attached both examples, I'm calling the first attempt the Column method and this second attempt using InitializeRow the Row method.
I'm hoping you can take a look and see what I'm screwing up now. I know this has been a long and time-consuming thread, and I really appreciate your continued help.
//dt.Columns.Add("FUNDING_SOURCES", typeof(List<object>));dt.Columns.Add("FUNDING_SOURCES", typeof(object));
Now funding source will be a column in the grid instead of a set of child bands. It still contains a list<object> though. Once I do this, it works fine, except that your checked column is never getting added because you are not hooking InitializeLayout on the Combo until after you have already set the data source. So you need to make sure you hook the event before you set the DataSource on the combo.
Infragistics - Mike Saltzman said:You can't do this on the grid, you would have to do it on your data object class so that the actual property returns an object.
These are probably stupid questions, but what property do I need to have return an object? Is this for the class T that is in the list?