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

ComboBox related question

Greetings, 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. Cheers, JF

7 Replies

AD Administrator Syncfusion Team January 12, 2005 10:10 PM UTC

Take a look at this KB. It discusses this problem. http://64.78.18.34/Support/article.aspx?id=567


JF Jim Frapper January 13, 2005 05:59 PM UTC

Hey Clay, 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[0]; 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[0].Rows.Count > 0) { PracticalService caller = new PracticalService(); int studentID = 0; foreach(DataRow row in this.data.Tables[0].Rows) { try { Practical arg = new Practical(); studentID = Convert.ToInt32(row[0].ToString()); PersonService ps = new PersonService(); Student student = ps.FindStudentByStudentID(studentID); arg.PersonInstanceID = student.PersonInstanceID.Value; arg.PracticalCategoryID = Convert.ToInt32(row[2].ToString()); arg.PracticalItemID = Convert.ToInt32(row[3].ToString()); arg.EditedByID.Value = Convert.ToInt32(row[4].ToString()); arg.Grade.Value = Convert.ToInt32(row[5].ToString()); arg.DateStamp.Value = Convert.ToDateTime(row[6].ToString()); caller.InsertPractical(arg); } catch (SqlException SqlEx) { log.Error(Data.DB.BuildExceptionString(SqlEx)); MessageBox.Show(Util.Messages.GeneralDBError); } } MessageBox.Show("Practical grades entered successfully."); // reinitialize the data in the grid this.data.Tables[0].Rows.Clear(); } } 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? JF


AD Administrator Syncfusion Team January 13, 2005 06:30 PM UTC

When you set the GridBoundColumn.StyleInfo for that column, do you set the DisplayMember and ValueMember and DataSource (and maybe CellValueType) for the column?


JF Jim Frapper January 13, 2005 08:44 PM UTC

>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[4].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. JF


AD Administrator Syncfusion Team January 13, 2005 09:14 PM UTC

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?


JF Jim Frapper January 14, 2005 01:10 PM UTC

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. JF


AD Administrator Syncfusion Team January 14, 2005 01:16 PM UTC

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.

Loader.
Live Chat Icon For mobile
Up arrow icon