combobox problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuvanand1
    New Member
    • Oct 2007
    • 22

    combobox problem

    Hai,
    Ihave a combobox and button in my application.Whe n i select an item in the combobox and click the button the item will be deleted and the message box shown the item deleted.My problem is that when i deleted the last item them will not deleted it exist in the combobox but the message box shown the item deleted.Then iagain open then the combobox is empty.What can i do? Please help me..........
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    kindly post your code for reference of our experts please.

    Comment

    • anuvanand1
      New Member
      • Oct 2007
      • 22

      #3
      [CODE=vbnet]Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
      Dim a As String
      If ComboBox1.Selec tedIndex <> -1 Then
      a = ComboBox1.Selec tedItem
      ComboBox1.Items .Remove(ComboBo x1.SelectedItem )
      MsgBox(a)



      End If



      End Sub[/CODE]
      Last edited by Shashi Sadasivan; Jan 25 '08, 06:10 AM. Reason: adding code tags

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        Originally posted by anuvanand1
        Hai,
        Ihave a combobox and button in my application.Whe n i select an item in the combobox and click the button the item will be deleted and the message box shown the item deleted.My problem is that when i deleted the last item them will not deleted it exist in the combobox but the message box shown the item deleted.Then iagain open then the combobox is empty.What can i do? Please help me..........
        So items should be deleted when they are selected?

        You did say that the combobox is empty after the last titem is selected!
        Whats the issue?

        Comment

        • anuvanand1
          New Member
          • Oct 2007
          • 22

          #5
          sir
          If I delete last element from the combobox it is deleting ,but the element is displayed in combobox ie it is not clearing the textarea of combobox

          for ex
          if i have elements 1 to 5 in combobox and if I delete serially the last element 5 is deleted but in combobox 5 is displayed

          plz neglect the previous code

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            Originally posted by anuvanand1
            sir
            If I delete last element from the combobox it is deleting ,but the element is displayed in combobox ie it is not clearing the textarea of combobox

            for ex
            if i have elements 1 to 5 in combobox and if I delete serially the last element 5 is deleted but in combobox 5 is displayed

            plz neglect the previous code
            What is your code then?

            the previous code looks as if it will do the job

            Comment

            • anuvanand1
              New Member
              • Oct 2007
              • 22

              #7
              [CODE=vbnet]Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
              Dim a As String
              ComboBox1.Items .Remove(ComboBo x1.SelectedItem )
              combobox1.refre sh()
              If ComboBox1.items .count=0 Then
              combobox1.items .clear()
              End If
              End Sub[/CODE]


              here is my code if I delete element one by one while deleting last element my combobox is not cleared
              Last edited by Shashi Sadasivan; Jan 25 '08, 10:56 AM. Reason: adding code tags

              Comment

              • Shashi Sadasivan
                Recognized Expert Top Contributor
                • Aug 2007
                • 1435

                #8
                Ok, I got what you meant
                the issue is that the text that is selected is different to selected items. the text can be edited regardless of the contents of the combo box

                try this (hope you can convert it to vb .net)

                [CODE=cpp]private void button1_Click(o bject sender, EventArgs e)
                {
                this.comboBox1. Items.Remove(th is.comboBox1.Se lectedItem);
                if (this.comboBox1 .Items.Count > 0)
                {
                this.comboBox1. SelectedIndex = 0;
                }
                else
                this.comboBox1. Text = "";
                }[/CODE]

                Comment

                Working...