We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridComboBoxCellRenderer setting the listbox items

Hi,

I have derived from GridComboBoxCellRenderer and GridComboBoxCellModel to create a custom combobox cell. Now I want to fill the combobox dynamically with different items. I thought I can use the constructor of the GridComboBoxCellRenderer derived class to add the items. But this doesn't work:

public class ExampleCellRenderer : GridComboBoxCellRenderer
{
public ExampleCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
: base(grid, cellModel)
{
ListBoxPart.Items.Clear();
ListBoxPart.Items.Add("ParameterValue2");
ListBoxPart.Items.Add("ParameterValue1");
}
....


Now when I click on the corresponding cell, I can't see the dropdown box with the items. Did I forgot something??

Thanks in advance,
Frank

3 Replies

AD Administrator Syncfusion Team November 29, 2006 10:30 AM UTC

Hi Frank,

You can override GridComboBoxCellRenderer. OnShowDropDown method and fill combobox cell dynamically with different items using ListBoxPart.Items property. Here is a code snippet to show this.

public class ExampleCellRenderer : GridComboBoxCellRenderer
{
public ExampleCellRenderer(GridControlBase grid, GridCellModelBase cellModel): base(grid, cellModel)
{
this.SupportsFocusControl = true;//cancel the editing in a cell
}

protected override void OnShowDropDown()
{
ListBoxPart.Items.Clear();
ListBoxPart.Items.Add("ParameterValue2");
ListBoxPart.Items.Add("ParameterValue1");
base.OnShowDropDown ();
}
}

Best Regards,
Haneef


AD Administrator Syncfusion Team November 29, 2006 02:40 PM UTC

Hi Haneef,

thanks for your sample. I have still the problem that nothing happens when I click on the combobox dropdown button. I have attached a sample where you can see the strange behavior. Just click on the "EnumValue2" cell.

Appendix:
It is currently implemented that the combobox button is only visible when the user clicks on the corresponding cell.

Thanks in advance

SyncfusionCustomCell.zip


AD Administrator Syncfusion Team November 30, 2006 08:43 AM UTC

Hi Frank,

To show the dropdown button only for the current cell, you need to set the ShowButtons property to GridShowButtons.ShowCurrentCell. Here is a modified code snippet to show this.

void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
Element eDisplayElement = e.TableCellIdentity.DisplayElement;
if (eDisplayElement.Kind == DisplayElementKind.Record && eDisplayElement.ParentTable != null)
{
if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "ObjectParameter")
{
GridRecordRow rec = e.TableCellIdentity.Table.DisplayElements[e.TableCellIdentity.RowIndex] as GridRecordRow;
if (rec != null)
{
MyData dr = rec.GetData() as MyData;
if (dr.ObjectParameter.GetType() == typeof(EnumParameter))
{
e.Style.CellType = "CustomCell";
e.Style.ShowButtons = Syncfusion.Windows.Forms.Grid.GridShowButtons.ShowCurrentCell;
}
}

}
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/SyncfusionCustomCell_9455b56e.zip

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon