code for listbox1 to listbox2 move on button clik

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajesh kunwar
    New Member
    • Jan 2010
    • 2

    code for listbox1 to listbox2 move on button clik

    how can retrive listbox1 to listbox2 without duplicate value
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Your goal and question are completely unclear.
    What is it that you need to accomplish?

    Comment

    • rajesh kunwar
      New Member
      • Jan 2010
      • 2

      #3
      how can add items listbox1 to listbox2 without duplicate items in c# codes.?

      I am use for this codes ,
      listbox1 to listbox2 without duplicate add items ,But this codes add items with duplicate entry.
      Code:
      private void button1_Click(object sender, EventArgs e)
              {
                  int  j;
                  for (int i = listBox1.Items.Count - 1; i >= 0; --i  )
                  {
                      j = listBox2.FindStringExact(listBox1.SelectedItem.ToString());
                      if (j == -1)
                      {
                          listBox2.Items.Add(listBox1.Items[i ]);
                      }
                      else
                      {
                          MessageBox.Show("It fields are already added");
                          return;
                       }
      Last edited by tlhintoq; Jan 31 '10, 05:35 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          So you want the item to appear to move from listbox1 to listbox2?
          In line 9 you add the item to listbox2
          Right after that remove it from listbox1
          Code:
          listBox1.Items.RemoveAt(i);
          If the ListBox is new to you, I might suggest you read up on it so you can better understand it. A complete list of its methods along with sample code are available on the MSDN.

          Comment

          Working...