View previous topic :: View next topic |
Author |
Message |
ewj
Joined: 28 Jun 2007 Posts: 1
|
Posted: Thu Jun 28, 2007 6:36 pm Post subject: CheckListBox as editor in VirtualTree |
|
|
I would like to use a CheckListBox as a cell editor. This list box would contain multiple items and support multiple selection. I can't figure out how to get the CheckedItemCollection property back from the editor control. Anyone have any hints?
Thanks,
Erik |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Jun 29, 2007 12:39 am Post subject: |
|
|
You need to add event handlers to the CellEditor SetControlValue and GetControlValue events. In these you map the CheckedItems to and from the data bound to the column. You will also need to handle the InitializeControl event to set up the items in the checked list. For example:
Code: | private void checkedListEditor_GetControlValue(object sender, CellEditorGetValueEventArgs e)
{
CheckedListBox clb = e.Control as CheckedListBox;
IList values = e.Value as IList;
foreach (object checkedItem in CheckedItems)
{
values.Add(checkedItem);
}
}
private void checkedListEditor_SetControlValue(object sender, CellEditorSetValueEventArgs e)
{
CheckedListBox clb = e.Control as CheckedListBox;
IList values = e.Value as IList;
foreach (object value in values)
{
int index = clb.Items.IndexOf(value);
if (index != -1)
{
clb.SetItemChecked(index, true);
}
}
}
private void checkedListEditor_InitializeControl(object sender, CellEditorInitializeEventArgs e)
{
CheckedListBox clb = e.Control as CheckedListBox;
clb.Items.Clear();
clb.Items.Add("Sydney");
clb.Items.Add("New York");
clb.Items.Add("London");
clb.Items.Add("Berlin");
} |
This assumes you have bound the column to a property that returns a list of the checked Items (in this case strings of city names).
I would also set the following properties on the CheckedListBox:
IntegralHeight = false;
CheckOnClick = true;
You will also need to set the height for the row to be sufficient to display the list. _________________ Infralution Support |
|
Back to top |
|
|
Ger83
Joined: 15 Sep 2009 Posts: 5 Location: Pretoria, South Africa
|
Posted: Wed Apr 11, 2012 1:07 pm Post subject: |
|
|
This post was a lot of help for me to use a CheckedListBox control as an cell editor.
Quote: | You will also need to set the height for the row to be sufficient to display the list. |
Could you please tell me how would I set the row height programatically when the control is displayed as is quoted above? |
|
Back to top |
|
|
Ger83
Joined: 15 Sep 2009 Posts: 5 Location: Pretoria, South Africa
|
Posted: Wed Apr 11, 2012 2:39 pm Post subject: |
|
|
Ger83 wrote: | This post was a lot of help for me to use a CheckedListBox control as an cell editor.
Quote: | You will also need to set the height for the row to be sufficient to display the list. |
Could you please tell me how would I set the row height programatically when the control is displayed as is quoted above? |
So what I've done is registered to the tree's GetRowData event and set
Code: | e.RowData.AutoFitHeight = true; |
But this does not change the row's height to fit the CheckedListBox control.
Any help? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Apr 12, 2012 12:03 am Post subject: |
|
|
AutoFitHeight only resizes based on text contained within the cell. It does not resize based on the size of displayed Editor control. Usually the Editor control is resized to fit the size of the cell (depending on the values of the CellEditor.UseCellWidth and CellEditor.UseCellHeight properties).
You will need to set the height of the row manually by setting the RowData.Height value (with AutoFitHeight false). _________________ Infralution Support |
|
Back to top |
|
|
|