Thread ID:

Created:

Updated:

Platform:

Replies:

Hi,
I have a GridGroupingControl. and i got 2 Colums in it. Col1 is a column containing Text. Col2 is a ComboBox Column. I want to set the value of the comboboxes in Col2 to specific values depending on the ones in col1.
I want to do this in the ctor (only once) a form is loaded.
I successfully looped the whole table but i''m unable to set the combobox index.
Here the code so far:
FieldDescriptor srcfield = m_syncGrid.TableDescriptor.Columns["DBETVT"].FieldDescriptor;
FieldDescriptor dstfield = m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].FieldDescriptor;
for (int i = 0; i < 10; i++)
{
if ( m_syncGrid.Table.Records[i].GetValue(srcfield).ToString().ToLower() == "e" )
{
GridStyleInfo style = m_syncGrid.TableModel[i, m_syncGrid.TableDescriptor.VisibleColumns.IndexOf(Constants.DataBase.col_ETVT)];
style.FormattedText = "ET";
//m_syncGrid.Table.Records[i].SetValue(srcfield, "ET");
}
//Console.WriteLine( m_syncGrid.Table.Records[i].GetValue(srcfield).ToString() );
}
Thanks,
Oliver

Try using m_syncGrid.Table.Records.Count to get the number of records.
I am a little confused about this combobox column. Is it bound to a column in the DataSource? If so, then setting its value is the same as setting the value directly in the data source and vice-versa since it is bound.
Are you trying to use some kind of foreign key relation to translates key values from the data source into display values that you want to see in the grid? If so, you can set the style.DisplayMember, style.ValueMember, style.DataSource on the column where you have set the style.CellType = "ComboBox".
If this is an unbound column, then you would dynamically provide the unbound value through the QueryValue event that is used to populate unbound columns.

Ok, let me describe the problem:
Maybe it helps me if I would know how to access the cell''s embedded Combobox and change it''s value.
But I think i have a problem here. Shortly before this is done the GridColumn is assigned to the celltype "combobox". Now I am trying to get a reference to the combobox with the following line:
ComboBox cmb = (ComboBox) m_syncGrid.Table.Records[i].GetValue("DBETVT");
The Combobox evaluates always as "undefined value".
The datasource for the combobox is a new datatable which doesn''t have anything in common with the Grid''s Datasource. See code below:
// Assign the ComboBoxes to this column
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.CellType = "ComboBox";
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.DropDownStyle = GridDropDownStyle.AutoComplete;
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.DataSource = Constants.DataBase.dt_ETVT;
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.DisplayMember = "Value";
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.ValueMember = "Key";
FieldDescriptor srcfield = m_syncGrid.TableDescriptor.Columns["DBETVT"].FieldDescriptor;
FieldDescriptor dstfield = m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].FieldDescriptor;
for (int i = 0; i < 10; i++)
{
if ( m_syncGrid.Table.Records[i].GetValue(srcfield).ToString().ToLower() == "e" )
{
GridStyleInfo style = m_syncGrid.TableModel[i, m_syncGrid.TableDescriptor.VisibleColumns.IndexOf(Constants.DataBase.col_ETVT)];
ComboBox cmb = (ComboBox) m_syncGrid.Table.Records[i].GetValue(Constants.DataBase.col_ETVT);
}
(srcfield).ToString() );
}
Hope i made myself clearer.

>>ComboBox cmb = (ComboBox) m_syncGrid.Table.Records[i].GetValue("DBETVT");
Did you save a Windows Forms ComboBox into the DBETVT column of the grid''s datasource?
If not, that is why the above code does not work.
The ''embedded combobox'' (and there is only one for all cells that use a combobox) is automatically populated for you using the style.DataSource that you provide for the cell. So, if you want to populate the ''embedded combobox'', then you do so by populating the DataSource you set for the cell''s Style.
You cannot think of a different Windows Forms ComboBox being in every cell that uses a combobox. In fact, there is only one such combobox, and it is shared among all cells that have CellType="CombBox".
To set the values that will show up in the combobox for that column, you need to set the values in Constants.DataBase.dt_ETVT. So, instead of trying to use code like
ComboBox cmb = (ComboBox) m_syncGrid.Table.Records[i].GetValue("DBETVT");
you should be populating the datasource for the combobox, Constants.DataBase.dt_ETVT. And to set a particular value into the cell, you should be setting the value in the Constants.DataBase.col_ETVT field of the m_syncGrid.Table.Records[i] record.
Normally, you do not have to worry about trying to set display values to be seen in the comboboxes dropdown. They should be automatically set by the grid for the information you provided in the columns Appearance property.

If you want to dynamically provide values for the combobox dropdown so they vary from cell to cell, then you should use the TableControlCurrentCellShowingDropDown event, and dynamically set the DataSource to the drop list at that point. There is a KB for doing this for a GridDataBoundGrid. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=115&catId=12

Ok, now i came up with the following:
foreach (Record rec in m_syncGrid.Table.Records)
{
Console.WriteLine(rec.GetValue(srcfield).ToString());
if (rec.GetValue(srcfield).ToString().ToUpper() == "E")
{
rec.SetValue("VarMarker", 1);
}
}
What would i have to set in the rec.SetValue line if the column "VarMarker" is a combobox column ?
Do i set the string to choose, the DataRow, the index ??
I tried a few possibilities but the Comboboxes always remain empty.
Thanks,
Oliver

From your code:
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.DataSource = Constants.DataBase.dt_ETVT;
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.DisplayMember = "Value";
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.ValueMember = "Key";
the value member of the combobox is something call "Key" which is a column in Constants.DataBase.dt_ETVT (assumed to be a DataTable). The value you set into the grid should be something like a "Key" object. So, if "Key" is an Int, then you should put an Int into the record. If "Key" is a string, you should put a string into the record. More over, the value you set must be an entry in the Constants.DataBase.dt_ETVT DataTable (otherwise the key would not be found in the look-up table).
Another comment is that the System.Type of the column in the grid must be the same as the System.Type of the "Key". So, if the "Key" column in Constants.DataBase.dt_ETVT holds an int, then column in the grid''s DataSource that maps to m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT] should also hold an int.
If you upload a sample you want to see working, I can try to tweak it for you.

Here is something you can try to home in on this problem. Comment out the line
m_syncGrid.TableDescriptor.Columns[Constants.DataBase.col_ETVT].Appearance.AnyRecordFieldCell.CellType = "ComboBox";
and run your project. Without the combobox celltype being set, you should just see whatever you are trying to set in that column in the grid. If this works, then the problem is likely on the combobox side of things. The first thing to do is to check the datasource of teh combobox to make sure it is what you expect. For example, you can drop a DataGrid on this form, and set its DataSource to be the combobox DataSource. Does it show what you expect?