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
close icon

Changing the choice list in GridDataBoundGrid

I have a GDBG that the third column of this grid is comboBox (cell type). I want to do two things: 1- When ever the user select his choice from comboBox list, I want to change the cell type to static with his selection. That means he can''t change his choice any more. I believe I have accomplish this task by CurrentCellCloseDropDown and QueryCellInfo events. 2- The second thing I want to do is a little bit tricky. Between my comboBox selection, if user selects for example "Classic Macro Name", I want to replace the current choice list with a new choice list and let user to select again from new choice list. Then as above when selection is complete I want to change the cell type to static. The problem is I am able to change the choice list to new list but this happens when I leave the cell and come back to the cell again not right away. Here is some of my code related to this issue: private void _TestGridDataBoundGrid_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e) { GridDataBoundGrid grid = sender as GridDataBoundGrid; int index; if(grid != null) { GridCurrentCell cc = grid.CurrentCell; GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; if(cc != null) { index = cr.ListBoxPart.SelectedIndex; if (index == 8) // Classic Macro Name { // I am not sure I need any of the following. I added based on different forum suggestion. this._TestGridDataBoundGrid.CurrentCell.ConfirmChanges(); this._TestGridDataBoundGrid.CurrentCell.EndEdit(); this._TestGridDataBoundGrid.Binder.EndEdit(); } } } } private void _TestGridDataBoundGrid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if(e.RowIndex > 0 && e.ColIndex == 3) { string comboboxText = e.Style.Text; if (comboboxText == "") { e.Style.ChoiceList = macroItems; } else { if(comboboxText == "Classic Macro Name") { e.Style.ChoiceList = classicMacroItems; // new choice list } else { e.Style.CellType = "Static"; e.Style.Text = comboboxText; ((TestGridRow) _testArray[e.RowIndex - 1]).Macro = comboboxText; // update the array list with the text. } } } }

4 Replies

AD Administrator Syncfusion Team January 10, 2006 07:39 AM UTC

Hi Najmeh, Here is a sample which, uses the CurrentCellShowingDropDown event to change the ChoiceList dynamically, the SaveCellInfo event stores the selected value in the array list and the PrepareViewStyleInfo event is used to set the cell style to ReadOnly/Static. Regards, Calvin.

39461.zip


NJ Najmeh Joze-khajavi January 11, 2006 04:34 PM UTC

Thank you very much for the sample. I have a couple questions. I see you use e.Style.ReadOnly = true instead of e.Style.CellType = "Static"; why is that? I think I read somewhere in forum that says to change the cell type it is better to do it in QueryCellInfo event rather than the PrepareViewStyleInfo event. Is this the reason? I prefer to change the cell type to "Static". The reason I prefer it is when we change the cell type we don''t see the tiny arrow button but when we change the readOnly properties the arrow button is still there. Another question is the valid choices for this comboBox as your sample are Macro1 to Macro5 and ClassicMacro1 to ClassicMacro5. So I need to make sure that our customer doesn''t end up to select "Macro Classic Name" and leave it like that. In which event I can test this or how I can prevent user to leave with "Macro Classic Name" selection?


AD Administrator Syncfusion Team January 12, 2006 05:08 AM UTC

Hi Najmeh, Static cells can be deleted by the user if the static cells are a part of the selection when the delete key is pressed. Since you have mentioned that the user should not able to change his/her choice after selecting once, I have used ReadOnly. To prevent this deletion behavior, set the cells to Read-only in addition to setting it to Static. As you have mentioned, to change the cell type the QueryCellInfo event is better. To know the difference between the QueryCellInfo and the PrepareViewStyleInfo you can refer the following link. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=96 By handling the gridDataBoundGrid1.CurrentCellValidating event you can avoid the user from selecting “Macro Classic Name”. I have attached the modified sample. Regards, Calvin.

39461_0.zip


NJ Najmeh Joze-khajavi January 13, 2006 04:38 PM UTC

Thank you.

Loader.
Live Chat Icon For mobile
Up arrow icon