Say I have a databound grid with two columns. One is called "Product Category" and the other is called "Product Items".
Upon loading of the grid I am populating the first column based on the available categories. This is of course a combobox column as will be the next column.
This grid will be used for bulk data entry and will initially be empty except for the previously loaded values for the Product Category.
When the category is selected, I will query the database and get the Product Items for that particular category and load up the Product Items column with this data.
I am having trouble getting the items loaded for a particular category for each row entered.
How do you dynamically load a combo box on a per row basis in a databound grid? Please let me know if more info is needed.
ADAdministrator Syncfusion Team January 12, 2005 05:10 PM
Take a look at this KB. It discusses this problem.
JFJim FrapperJanuary 13, 2005 12:59 PM
I have 95% of it working, but need a little help with the last 5%.
Here is what I have in the CurrentCellShowingDropDown event:
private void gridData_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e)
GridCurrentCell cc = this.gridData.CurrentCell;
if (cc.ColIndex == 4)
int categoryID = Convert.ToInt32(this.gridData[cc.RowIndex, 3].Text);
PracticalService caller = new PracticalService();
DataSet items = caller.FindItemListByCategoryAndGeoID(categoryID, ((MDI)this.ParentForm).GeoID);
GridComboBoxCellRenderer render = (GridComboBoxCellRenderer)cc.Renderer;
GridComboBoxListBoxPart part = (GridComboBoxListBoxPart)render.ListBoxPart;
part.DataSource = items.Tables;
part.DisplayMember = "Name";
part.ValueMember = "PracticalItemID";
This is working great. However, when I go to write the data for the grid(this is a bulk entry screen) The value for my item column is the Name field and not the PracticalItemID. Here is my write to db function:
private void addData()
if (this.data.Tables.Rows.Count > 0)
PracticalService caller = new PracticalService();
int studentID = 0;
foreach(DataRow row in this.data.Tables.Rows)
Practical arg = new Practical();
studentID = Convert.ToInt32(row.ToString());
PersonService ps = new PersonService();
Student student = ps.FindStudentByStudentID(studentID);
arg.PersonInstanceID = student.PersonInstanceID.Value;
arg.PracticalCategoryID = Convert.ToInt32(row.ToString());
arg.PracticalItemID = Convert.ToInt32(row.ToString());
arg.EditedByID.Value = Convert.ToInt32(row.ToString());
arg.Grade.Value = Convert.ToInt32(row.ToString());
arg.DateStamp.Value = Convert.ToDateTime(row.ToString());
catch (SqlException SqlEx)
MessageBox.Show("Practical grades entered successfully.");
// reinitialize the data in the grid
For my other combobox columns, as you can see, I just use Convert.ToInt32(row[x].ToString()) and it will give me the ValueMember. But, with my new dymamic combo I get the DisplayMember. How do I get to the ValueMember for my new dynamic combo column?
ADAdministrator Syncfusion Team January 13, 2005 01:30 PM
When you set the GridBoundColumn.StyleInfo for that column, do you set the DisplayMember and ValueMember and DataSource (and maybe CellValueType) for the column?
JFJim FrapperJanuary 13, 2005 03:44 PM
>When you set the GridBoundColumn.StyleInfo for that column, do you set the DisplayMember and ValueMember and DataSource (and maybe CellValueType) for the column?
When the grid is initialized, I just use the following line:
this.gridData.Model.ColStyles.CellType = "ComboBox";
Since its empty when its initialized, there is not datasource, display, or value member. It only gets populated in the CurrentCellShowingDropDown event shown above.
Note: A point of confusion is that I didn''t use the dataview technique in the sample. I am loading this column from the db for each row in real time utilizing a datatable.
ADAdministrator Syncfusion Team January 13, 2005 04:14 PM
I think you will have to set the valuemember/displaymember/datasource properties for the column as well. Can you set the datasource to be all the possible values for any of the individual cell lists?
JFJim FrapperJanuary 14, 2005 08:10 AM
If what I have prototyped above does not work with the DisplayMember and the ValueMember, I will have no other choice than to put all the values in the combo and utilize your dataview method.
I wanted to avoid putting all the possible items in the combo for performance and memory reasons. My application resides on a terminal server box, so memory consumption is at a premium. I try to cut small corners like this when I can. If you can''t get my prototyped code to work, then by the end of today I will go with the alternate method.
Thanks for your help Clay.
ADAdministrator Syncfusion Team January 14, 2005 08:16 AM
You sort of have to do this because if you only populate the lookup table after the cell is dropped, how can the grid draw the displaymember in the cell initially (as the cell has never been dropped at this point). The column needs to have the information set so the grid can map the valuemember it knows to the proper displaymember even if the cell is never dropped.