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.
jammerms said: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.
I can see how storing the list of sources as child rows makes sense from the perspective of the data source, but it doesn't really work for the grid or the display. Basically, in order to have a dropdown checklist in the grid, the cell's value has to contain a concatenated list of the checked values. However you do it, the parent band has to have all of the checked values in a single cell.
So the ideal thing would be to store a list of Source ID's in a single cell of the Contracts table.
But if you don't want to change your data structure, what you could do is hide the child band in the grid using the Hidden property on the band. Then add an unbound column to the root band and use the InitializeRow event to populate the unbound cell with the list of values based on the child rows which are still there, but hidden.
Going the other way, you would have to handle what happens when user updates the unbound cell. So you would probably use the AfterRowUpdate event for that. You would examine the new value of the "sources" cell and you would have to update your data source to link up the correct sources with the correct parent row.
Mike,
First, let me say that I've figured out why quoting from your posts doesn't seem to work properly: Infragistics employees' names all have '[Infragistics]' automatically inserted at the front, and the extra brackets break the string parse. So quoting you has the following:
Mike Saltzman"]Your text here.
Infragistics Mike Saltzman said: Basically, in order to have a dropdown checklist in the grid, the cell's value has to contain a concatenated list of the checked values. However you do it, the parent band has to have all of the checked values in a single cell. So the ideal thing would be to store a list of Source ID's in a single cell of the Contracts table.
Basically, in order to have a dropdown checklist in the grid, the cell's value has to contain a concatenated list of the checked values. However you do it, the parent band has to have all of the checked values in a single cell.
So should I ever even set the datasource for the dropdown used as the columns editor? If I set a List<int> of funding source IDs as the value of the cell, is that just the list of checked items? So then do I set the datasource of the dropdown to be just the full list of possible funding sources, and the grid will check the right ones based on the value of the cell?
Or should I do this: use a List<FundingSource> as the value for each cell, with FundingSource as a class that has public properties int ID, string Name, and bool Checked, and set the dropdown's ValueMember to "ID", DisplayMember to "Name", and CheckStateMember to "Checked"?
By the way, I am instantiating an UltraCombo in the constructor (and adding it to the forms controls collection) and setting it to be the Funding Source column's editor control in the grid's InitializeLayout event. I am using the combo's InitializeLayout to format the columns in the dropdown. Hope this is optimal.
Thanks for all you patience with this. Don't hesitate to dumb it down for me.
--J
jammerms said:First, let me say that I've figured out why quoting from your posts doesn't seem to work properly: Infragistics employees' names all have '[Infragistics]' automatically inserted at the front, and the extra brackets break the string parse. So quoting you has the following: Mike Saltzman"]Your text here.. If I manually remove the brackets around 'Infragistics', it works, like so: Yes, we know. Our IS team is still trying to figure out what to do about this. :) jammerms said:So should I ever even set the datasource for the dropdown used as the columns editor? If I set a List<int> of funding source IDs as the value of the cell, is that just the list of checked items? So then do I set the datasource of the dropdown to be just the full list of possible funding sources, and the grid will check the right ones based on the value of the cell? The DataSource of the ValueList or DropDown just determines the items that appear on the list. So there is still a reason to DataBind it to a data source of some kind. And yes, if the cell contains a concatenated list of values, then the correct ones should be checked when you drop it down.
Mike Saltzman"]Your text here.. If I manually remove the brackets around 'Infragistics', it works, like so:
Yes, we know. Our IS team is still trying to figure out what to do about this. :)
jammerms said:So should I ever even set the datasource for the dropdown used as the columns editor? If I set a List<int> of funding source IDs as the value of the cell, is that just the list of checked items? So then do I set the datasource of the dropdown to be just the full list of possible funding sources, and the grid will check the right ones based on the value of the cell?
The DataSource of the ValueList or DropDown just determines the items that appear on the list. So there is still a reason to DataBind it to a data source of some kind. And yes, if the cell contains a concatenated list of values, then the correct ones should be checked when you drop it down.
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?