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

Dynamically modifying the choice list of a combobox

Hi I am trying to modify the choice list of a combobox dynamically depending on the user's action. When the user chooses the "More..." option I want the combo box to be populated from an Enumeration and when the user chooses the "Less..." option I want the combobox to be populated with a predefines StringCollection. I try to do this by catching the CurrentCellChanged event. My code for doing this is as follows: ****************************************** private void gridControl1_CurrentCellChanged(object sender, System.EventArgs e) { int colindex = gridControl1.CurrentCell.ColIndex; if(colindex != 2) //To check if it was the type combobox return; int rowindex = gridControl1.CurrentCell.RowIndex; GridCurrentCell cc = gridControl1.CurrentCell; string newValue = cc.Renderer.ControlText; //string oldValue = this.grid[cc.RowIndex, cc.ColIndex].Text; if(newValue == "More ...") { gridControl1[rowindex,2].ChoiceList.Clear(); for (TubularComponentEnum enumValue = TubularComponentEnum.ABSENT_VALUE; enumValue <= TubularComponentEnum.Vertical; enumValue++) { gridControl1[rowindex,2].ChoiceList.Add(enumValue.ToString()); } gridControl1[rowindex,2].ChoiceList.Add("Less ..."); gridControl1.Refresh(); } if(newValue == "Less ...") { gridControl1[rowindex,2].ChoiceList.Clear(); gridControl1[rowindex,2].ChoiceList = items; gridControl1.Refresh(); } } ********************************************* The problem that I am having is that If the user chooses the "more..." option in the combobox of row 1 then the change happens in the combobox of row 2 but not in the combobox of row1. Also after one cycle of user choosing "More..." and "Less..." the choice list of the comboboxes in the entire column become empty. Please comment on what I am doing wrong. I have attached my code with this post. thanks for your help. regards, Sachin.

3 Replies

AD Administrator Syncfusion Team May 7, 2003 01:50 PM UTC

I made these three changes to your code. 1) In the constructor I set the list for the first row. //set the first row gridControl1[1,2].ChoiceList = items; 2) In your CurrentCellActivated, I set the list for the newly added row, instead of the current row. The reason is that you don't want to be dynamically changing style setting for a cell while it might be activating. 3) I tweaked your CurrentCellChanged code. I added a call to ConfirmChanges so teh cahnge would be stored in the grid. I also remove your calls to Clear. The reason is that these were sttepping on your single items list, so it was no longer available. I have attached the changes.


SB Sachin Bammi May 7, 2003 03:11 PM UTC

Clay, Thanks a bunch for your help! regards, -Sachin.


SB Sachin Bammi May 7, 2003 09:27 PM UTC

Clay, The changes you suggested work fine for a regular grid control. However when I change the grid control to a virtual grid control so that it could handle data they do not work any more. forexample: the following statement gridControl1[rowindex,2].ChoiceList = new StringCollection(); Does not change the ChoiceList.Count to 0 anymore as it used to earlier. Similary, the follwoing statement m_GridControl[cc.RowIndex,2].ChoiceList = items; in the if loop ***if(newValue == "Less ...")*** has no effect on the ChoiceList. I tried catching any uncaught exceptions that may have been thrown but there weren't any. I would appreciate any insights from your side. regards, Sachin.

Loader.
Live Chat Icon For mobile
Up arrow icon