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

ComboBox renderer for gridBoundColumn

Hi,
I am using your grid and attached comboBox renderer to one of the grid bound columns.
I filled the comboBox with my values by using choiseList.
My problem is when I select one of the options in the comboBox I don't see the chosen item in the cell.
I can I make the renderer to show me the chosen item in the text of the cell.

My second problem is how I register to the event of "changing of the selected item" and how I get the new value of the selected item.

thanks,
Yoni


5 Replies

HA haneefm Syncfusion Team December 26, 2007 10:59 PM UTC

Hi Yoni,

1. How I register to the event of "changing of the selected item"
>>>>>>
You can register the SelectedValueChanged event with the help of the gridcell Renderer. Please refer this code snippets:

GridCurrentCell cc = e.TableControl.CurrentCell;
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if( cr != null)
{
cr.ListBoxPart.SelectedValueChanged+=new EventHandler(ListBoxPart_SelectedValueChanged);
}

2.How I get the new value of the selected item?
>>>>>>
You can get the value of the SelectedItem in the combobox using the ListBoxPart.SelectedValue. You have to handle CurrentCellCloseDropDown event to get this working. Please refer to the following code snippet

void gridDataBoundGrid1_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e)
{

if (e.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;

GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;

if (cr != null)
{
Console.WriteLine(cr.ListBoxPart.SelectedValue);
}
}
}

3. When making a selection in the combobox cell, the selected value appears properly in a grid. Please refer to the attached sample, and here you can show the selected value in the grid cell.

Sample: http://www.syncfusion.com/Support/user/uploads/GDBG_Combo_cf4500d2.zip

Best regards,
Haneef



YO Yoni December 27, 2007 09:14 PM UTC

I forgot to say that I use gridDataBoundGrid.
I attached to this grid's DataSource a dataTable, and tried to choose a specifiec cell and to change by the code it's cellType and to add ChoiceList. By debugging my code I figured out that somehow this properties don't accept my changes, they stay as they were before I tried to change them. Only the text Property changed.

gridDataBoundGrid1[1,2].Text = "HelloWorld"
gridDataBoundGrid1[1,2].CellType = "ComboBox"
gridDataBoundGrid1[1,2].ChoiceList = items
//items is a stringCollection object.

The text has been changed.
CellType had been "TextBox" and
choiseList had been null. After running the code they stayed the same.

Can you help me to figure why I can't change this properties ?

thanks,
Yoni



HA haneefm Syncfusion Team December 27, 2007 10:00 PM UTC

Hi Yoni,

By default, DataBoundGrid doesn't store any style info properties. You can not set any cell or row specific properties for the DataBoundGrid using Model Indexer other than the CellValue. You need to handle the PrepareViewStyleInfo (or Model.QueryCellInfo) Event to do this. Through this event you can set the style properties for the grid.

To set the CellType for a cell, you check for the e.RowIndex/e.ColIndex, if that points to the row you desired, set the e.Style.CellType for it.

If you want to set the cell style property in a grid then call the Refresh or RefreshRange method to fire the QueryCellInfo event to set the style settings of the cell in a grid.

See the KnowledgeBase Articles for more info.
QueryCellInfo event : http://www.syncfusion.com/Support/article.aspx?id=10351
PrepareViewStyleInfo event :http://www.syncfusion.com/Support/article.aspx?id=560

Best regards,
Haneef



YO Yoni December 28, 2007 09:03 AM UTC

Thank you that was very helpfull.
But I don't understand why you blocked the probability to change these cells' style properties outside from these events.
Does it have a reason ?

thanks again,
Yoni



HA haneefm Syncfusion Team December 28, 2007 07:06 PM UTC

Hi Yoni,

GridDataBoundGrid is a column oriented grid( bounded to a datsource) that stores style info properties for grid column. But it doesn't store any style info properties for a cell. You can not set any cell or row specific properties for the DataBoundGrid using Model Indexer other than the CellValue.

Best regards,
Haneef


Loader.
Live Chat Icon For mobile
Up arrow icon