How to remove used items from combobox cell type in grid ?

Posted by: manish-tewary on 8 September 2017, 2:54 pm EST

  • Posted 8 September 2017, 2:54 pm EST

    I have a grid with a combobx cell type .


    All  I want is that when i user click on the dropdown to select any item, the items which are already selected should not come in the current row. Also, if the user changes any of the previous defined values then dropdown should be updated accordingly.


    e.g, lets say dropdown has 4 item: "A", "B", "C" and "D".


    For the first row if the user selects item "A", then when it clicks on the dropdown in the subsequent rows item "A" should not appear in the list. Now suppose the user selects "B" for the second row and then immeditely jumps to dropdown at the first row then both the items "A" and "B" should not be there.


     

  • Replied 8 September 2017, 2:54 pm EST

    wasn't easy, but this does it.

    namespace WindowsFormsApplication23

    {

        public partial class Form1 : Form

        {

            public
    Form1()

            {

                InitializeComponent();

            }

     

            private
    void Form1_Load(object
    sender, EventArgs e)

            {

                string[]
    array = { "A", "B", "C",
    "D" };

                FarPoint.Win.Spread.CellType.ComboBoxCellType cmbx = new
    FarPoint.Win.Spread.CellType.ComboBoxCellType();

                cmbx.Items = array;

      
             fpSpread1.ActiveSheet.Columns[1].CellType
    = cmbx;

            }

     

            private
    void fpSpread1_ComboCloseUp(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)

            {

                //Get a
    reference to the CellType

                FarPoint.Win.Spread.CellType.ComboBoxCellType cbct =

                    (FarPoint.Win.Spread.CellType.ComboBoxCellType)fpSpread1.ActiveSheet.Columns[e.Column].CellType;

                //Instantiate
    an ArrayList for ease of array operations

                System.Collections.ArrayList
    list = new System.Collections.ArrayList();

                //Add the
    combo Items to the ArrayList

                for
    (int i = 0; i < cbct.Items.Length; i++)

                    list.Add(cbct.Items[i ]);

                //Get the
    selected object

                object
    selection = fpSpread1.ActiveSheet.Cells[e.Row, e.Column].Value;

                //Remove
    selection from ArrayList

                list.Remove(selection);

                //create
    a string array from the arraylist

                string[]
    array = list.ToArray(typeof(string)) as string[];

                //Instantiate
    a new combobox celltype

                FarPoint.Win.Spread.CellType.ComboBoxCellType cmbx = new
    FarPoint.Win.Spread.CellType.ComboBoxCellType();

                cmbx.Items = array;

      
             //assign
    to the column

               
    fpSpread1.ActiveSheet.Columns[1].CellType = cmbx;

            }

        }                   

    }



  • Replied 8 September 2017, 2:54 pm EST

    Hi,


    above code is not working properly.


    You have removed the currently selected object for the array list and then assigning this array to the combobox celltype then how come the currently selected object will be shown in the current combobox.


    Also, this will not work for multiple rows. Kindly check


     

  • Replied 8 September 2017, 2:54 pm EST

    Hello,

    I would like you to know that what you are seeing is the intended behavior, once you remove an item from the drop down list of the ComboBox it would no more show up as a value in the ComboBox cell as the value no longer exists in the list. So, the only workaround possible would be to display, the current selected value in the cell, along with the remaining items that are not selected, whenever the ComboBox list is dropped down.

    I have attached a sample that depicts the same, kindly have a look at it, hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur


    2012/03/combodropdown.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels