Home Forums WinForms controls Xceed Grid for WinForms ValueMember in bound ComboBox Reply To: ValueMember in bound ComboBox

User (Old forums)
Member
Post count: 23064

There is a CellEditorViewer, but only to set colouring. I tried not using it and it makes no difference.

Ok, so I can’t send you a full sample as I explained, but here is all you should need:

 – Grid column is set like this:

 ComboBoxEditor myCombo = new ComboBoxEditor();

myCombo.TemplateControl.DropDownControl.ScrollBars = GridScrollBars.None;

height = gridBasketControl.Font.Height * 5;

myCombo.TemplateControl.DropDownSize = new Size(gridBasketControl.Columns[“MyColumn”].Width, height);

gridBasketControl.Columns[“MyColumn”].CellEditorManager = myCombo;

– The databinding is different for each row, so I can’t set it at the template control level, so I set it on activating event:

 void MyCellEditorManager_ActivatingControl(object sender, CellEditorEventArgs e)

        {

            WinComboBox combo = e.Control as WinComboBox;

            combo.DisplayFormat = “%Key%”;

            combo.SetDataBinding(dataSet, “TableName”);

            combo.ValueMember = “Value”;

            combo.DropDownControl.Columns[“Value”].Visible = false;

        }

 

 – Here is the dataset I’m binding to, consisting of one table:

DataSet dataSet = new DataSet();

dataSet.Tables.Add(new DataTable(“TableName”));

dataSet.Tables[“TableName”].Columns.Add(new DataColumn(“Key”));

dataSet.Tables[“TableName”].Columns[0].AllowDBNull = false;

dataSet.Tables[“TableName”].Columns[0].Unique = false;


dataSet.Tables[“TableName”].Columns.Add(new DataColumn(“Value”));

dataSet.Tables[“TableName”].Columns[1].AllowDBNull = false;

dataSet.Tables[“TableName”].Columns[1].Unique = false;


dataSet.Tables[“TableName”].Rows.Add(new object[] { “Key1”, “value1” });

dataSet.Tables[“TableName”].Rows.Add(new object[] { “Key2”, “value2” });

 

So the expected behaviour, is this:

1) When you click on this column, you get the combox box showing “Key1” and “Key2”.

2) When this cell loses focus, whatever was selected stays there!

3) I am able to retrieve the *values* (value1 or value2) depending on what was selected.

 

The actual behaviour is:

1) Works fine.

2) Once you click away, the VALUE is displayed! So eg value1 replaces Key1. Additionally, if I try and click back again, the combobox will not appear again and the activating event will never fire again.

3) As per my initial post, I am unable to get the value programatically from within the code. I need to just get either value1 or value 2 as per what is selected.

 

Thanks for your help in how to resolve these. 

 

 

 

 

Imported from legacy forums. Posted by Nigel (had 322 views)