I had a need for a combobox that allowed multiselect and checkbox. WebCombo was very close to what I needed, with some simple code i was able to achieve this functionality so i figured i would share with others who may be interested.
Steps:
Drop a webcombo on your form:
In page_load add the following code: ( I set properties in code for webcombo)
{
tbl.Columns.Add(
}
WebCombo1.DataSource = tbl;
WebCombo1.DataBind();
grid.DisplayLayout.ClientSideEvents.CellClickHandler =
grid.Columns.FromKey(
grid.DisplayLayout.ActivationObject.BorderStyle =
WebCombo1.ClientSideEvents.BeforeCloseUp =
WebCombo1.DropDownLayout.RowSelectors =
WebCombo1.DropDownLayout.ColHeadersVisible =
WebCombo1.DropDownLayout.FrameStyle.BackColor = System.Drawing.
Then add the following javascript section to handle clientside events:
//display the text in the combo text box
combo.setDisplayValue(displayText);
boolCell.setValue(!boolCell.getValue());
cancelClose=
That should do it.
Some slight modifications will need to be made for you coumn names/numbers
To retrieve values on client, use a functioin such as:
selectedValues[aCnt]=row.getCell(0).getValue();
selectedText[aCnt]=row.getCell(2).getValue();
aCnt++;
To get selected values on the server, the following would do it:
//listbox is a ListBox server control
I also attached the project to this post.
Here is what it looks like:
Thanks for sharing!
If only this have been posted earlier it would have saved me a lot of time :) I just posted about my own multiselect combo a while ago to help out on another post here in the forums only to find out about this post which came days earlier.
Anyways, I'd still definitely get a lot from this.
I seem to ran into an odd behavior though if clicking directly on the checkbox. For example, right after the page loads and I dropdown the combo and click on a checkbox, it seems to close up right away instead of the normal behavior of allowing another selection. And also, same but more pronounced issue when using firefox. Any chance you could look into it too.
I used an unbound Checkbox column (instead of a boolean datacolumn) but firefox doesn't seem to persist when page is posted back to the server so had to use some work around so if you could look into the one above it would be great. As the stuff i coded to keep the dropdown from closing I would have to say could use some improvement.
I'm running into the same problem, where if you click directly onto the checkbox the dropdownlist closes up after clicking on the first item. I tried hooking the GridBeforeCellUpdateHandler to set cancelClose to true, but this did not help. Any idea what event I need to hook in order to catch this?
uptongl said:I'm running into the same problem, where if you click directly onto the checkbox the dropdownlist closes up after clicking on the first item. I tried hooking the GridBeforeCellUpdateHandler to set cancelClose to true, but this did not help. Any idea what event I need to hook in order to catch this?
Hi uptongl,
I had a different approach for this one but if it would help you can have a look here http://ryangaraygay.com/blog/post/2008/03/Multiselect-WebCombo-(Infragistics).aspx
I'd have to say it's obviously not perfect and have all features but it seems to work for me so far so you might gain an idea or two to make it work better.
I found that by tweaking the GridCellClickHandler I got this bug fixed:
function GridCellClickHandler(gridName, cellId, button){ //Changes checkbox selection on any cell click in the row cancelClose=true; var cell=igtbl_getCellById(cellId); var boolCell=cell.Row.getCell(1); if(cell.Index!=1) boolCell.setValue(!boolCell.getValue());}