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.
Unfortunately, activation email could not send to your email. Please try again.

Dynamically modifying the choice list of a combobox

Thread ID:

Created:

Updated:

Platform:

Replies:

4311 May 7,2003 08:32 AM May 7,2003 05:27 PM Windows Forms 3
loading
Tags: GridControl
Sachin Bammi
Asked On May 7, 2003 08:32 AM

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.

Administrator [Syncfusion]
Replied On May 7, 2003 09:50 AM

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.

Sachin Bammi
Replied On May 7, 2003 11:11 AM

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

Sachin Bammi
Replied On May 7, 2003 05:27 PM

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.

CONFIRMATION

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.

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.

;