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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changing the choice list in GridDataBoundGrid

Thread ID:





39461 Jan 9,2006 03:21 PM UTC Jan 13,2006 04:38 PM UTC WinForms 4
Tags: GridControl
Najmeh Joze-khajavi
Asked On January 9, 2006 03:21 PM UTC

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

Administrator [Syncfusion]
Replied On 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.


Najmeh Joze-khajavi
Replied On 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?

Administrator [Syncfusion]
Replied On 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.


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

Thank you.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon