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

grid drop down

I have a question regarding databinding dropdowns in a grid vs the cells that are prepopulated above the entry dropdown. I have a grid that contains say 10 rows of colors. The last record is the editable row which contains a drop down of the available colors to pick from. I also have a dropdown outside the grid below that lets you filter out what rows are listed above to view. The drop down in the grid and outside the grid have different data adapters to handle this. This is done so that the user can enter new rows with a restricted amount of colors, but they can view all colors that have ever been entered. What is happening is the dropdown in the grid has 5 colors, the drop down outside determining what should be displayed in the grid has 10 ... however the other 5 never display because the values are not bound to the cells since that binding happens from the dropdown in the grid. The dropdown within the grid and the cells for the rows above it seem to pull from the same datasource. I would like to separate that so that the cells above can map to the datasource from my dropdown outside of the grid. Does anyone know if this is possible and how to do it? Thanks, Curtis

2 Replies

AD Administrator Syncfusion Team June 9, 2006 05:47 AM UTC

Hi Curtis , Could you try this code to add the item(colors) in a dropdown of the grid using the grid''s CurrentCellShowingDropDown event. Here is a code snippet, private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; if(cr != null ) { cc.BeginEdit(true); // DropDown inside Grid DataTable GridDropDown = cr.ListBoxPart.DataSource as DataTable; //Outside DropDown DataTable DataTable ComboTable = this.comboBox1.DataSource as DataTable; //change the DataSource Depends upon the outside DropDown" if(ComboTable != null) { for(int i = 0 ;i < ComboTable.Rows.Count;i++) { DataRow crow = ComboTable.Rows[i]; bool isExist = false; for(int j = 0 ;j < GridDropDown.Rows.Count;j++) { //ColorItem is the DisplayMember of the combo and GridcomboBox. if(crow["ColorItem"] == GridDropDown.Rows[0]["ColorItem"] ) { isExist = true; break; } } if(!isExist) { DataRow dr1 = GridDropDown.NewRow(); dr1[1] = crow["ColorItem"]; GridDropDown.Rows.Add(dr1); } } } cr.ListBoxPart.DataSource = GridDropDown; cc.EndEdit(); } } Let me know if this helps. Best Regards, Haneef


CG Curtis Gulick June 23, 2006 07:29 PM UTC

Haneef, this worked! Thanks! >Hi Curtis , > >Could you try this code to add the item(colors) in a dropdown of the grid using the grid''s CurrentCellShowingDropDown event. Here is a code snippet, > >private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e) >{ > GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; > GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; > > if(cr != null ) > { > cc.BeginEdit(true); > > // DropDown inside Grid > DataTable GridDropDown = cr.ListBoxPart.DataSource as DataTable; > > //Outside DropDown DataTable > DataTable ComboTable = this.comboBox1.DataSource as DataTable; > > //change the DataSource Depends upon the outside DropDown" > if(ComboTable != null) > { > for(int i = 0 ;i < ComboTable.Rows.Count;i++) > { > DataRow crow = ComboTable.Rows[i]; > bool isExist = false; > for(int j = 0 ;j < GridDropDown.Rows.Count;j++) > { > //ColorItem is the DisplayMember of the combo and GridcomboBox. > if(crow["ColorItem"] == GridDropDown.Rows[0]["ColorItem"] ) > { > isExist = true; > break; > } > } > if(!isExist) > { > DataRow dr1 = GridDropDown.NewRow(); > dr1[1] = crow["ColorItem"]; > GridDropDown.Rows.Add(dr1); > } > } > } > cr.ListBoxPart.DataSource = GridDropDown; > cc.EndEdit(); > } >} > >Let me know if this helps. >Best Regards, >Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon