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
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
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.
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 the ideal thing would be to store a list of Source ID's in a single cell of the Contracts table.
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
Hi J,
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.
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.
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.