Changing GridDataBoundGrid Cell DataSource at runtime

I was wondering if anyone could help me change the value of a cell''s datasource, in a GridDataboundGrid, at runtime. I would like to use a default datasouce for the column, but be able to change the datasource if the user checks a box in a column in the same row. I have tried the following, but it does not work: private void gdbServer_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { int row = e.RowIndex; int col = e.ColIndex; if ( col == 2 && row > 0 ) { string sPass = this.gridDataBoundGrid[ row, 3 ].CellValue.ToString(); if ( sPass == "N" ) { e.Style.DataSource = this.dataViewA; } if ( sPass == "Y" ) { e.Style.DataSource = this.dataViewB; } } }

2 Replies

AD Administrator Syncfusion Team February 23, 2004 04:18 PM UTC

Try using the grid.Model.QueryCellInfo event instead of the grid.PrepareViewStyleInfo event. If that does not work for you, you can use the grid.CurrentCellShwoingDropDown event as discussed in this KB, http://www.syncfusion.com/Support/article.aspx?id=567


AD Administrator Syncfusion Team February 23, 2004 05:41 PM UTC

Thanks, the CurrentCellShowingDropDown event worked for me. Here is how I did it, in case anyone else is curious. private void gdbServer_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e) { GridCurrentCell cc = this.gdbServer.CurrentCell; int row = cc.RowIndex; int col = cc.ColIndex; if( col == 2 ) { GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; if( cr != null ) { string sPass = this.gridDataBoundGrid[ row, 3 ].CellValue.ToString(); if ( sPass == "N" ) { ((GridComboBoxListBoxPart)cr.ListBoxPart).DataSource = this.dataViewA; } if ( sPass == "Y" ) { ((GridComboBoxListBoxPart)cr.ListBoxPart).DataSource = this.dataViewB; } } } }

Loader.
Up arrow icon