when selected combo item then the item delete from comobox?

Posted by: smartzq on 8 September 2017, 2:34 pm EST

  • Posted 8 September 2017, 2:34 pm EST

    there are four items in combo: "no use","one","two","three" , when I selected "one" in combox then this item  was delete from combo.Other combo cell only display "no use","two","three".


    if I change the "one" to "no use" then the other combo cell display "no use", "one","two","three"


    the "no use" item is always display in combo.


     


    thanks


    2011/02/3.JPG
  • Replied 8 September 2017, 2:34 pm EST

    Hello,

    Can you send us the sample replicating the issue because this seems to be an issue with the way ComboboxCellTypes items have been set. We need to look at the code in order to proceed further.

    Thanks.

  • Replied 8 September 2017, 2:34 pm EST

    I wrote these codes ,but I think maybe have better codes to solve .and I want to know how to use ".remove" and ".add".


    thanks


        Private Sub FpSpread1_CellClick(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick
            Dim combobox As New FarPoint.Win.Spread.CellType.ComboBoxCellType
            combobox.Items = New String() {"no use", "one", "two", "three"}
            Dim m As Integer
            Dim n As Integer = 0
            For m = 0 To FpSpread1.ActiveSheet.RowCount - 1
                If FpSpread1.ActiveSheet.Cells(m, 0).Value = "one" Then
                    combobox.Items = New String() {"no use", "two", "three"}
                    n = 1
                End If
            Next
            If n = 0 Then
                combobox.Items = New String() {"no use", "one", "two", "three"}


            End If
            FpSpread1.ActiveSheet.Cells(e.Row, 0).CellType = combobox
        End Sub

  • Replied 8 September 2017, 2:34 pm EST

    Hello,

    Here is a better way to achieve the required functionality using ComboSelChange method and EditingControl. Please have a look at the code:-

            FarPoint.Win.Spread.CellType.ComboBoxCellType combobox;

            string[] cbstr;

            public Form2()

            {

                InitializeComponent();

                cbstr = new String[] { "no use", "one", "two", "three" };

            }

     
            private void Form2_Load(object sender, EventArgs e)

            {

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

                combobox.Items = cbstr;

                fpSpread1.ComboSelChange+=new FarPoint.Win.Spread.EditorNotifyEventHandler(fpSpread1_ComboSelChange);

            }

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

            {

                FarPoint.Win.FpCombo combo = (FarPoint.Win.FpCombo)e.EditingControl;

                string value = ((FarPoint.Win.FpCombo)e.EditingControl).SelectedItem.ToString();

                if (value == "one")

                    combobox.RemoveItem(1);

                else

                    combobox.Items = cbstr;

            }

    Hope this will help you. Thanks.

Need extra support?

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

Learn More

Forum Channels