2 Replies - 390 Views - Last Post: 01 December 2012 - 08:14 AM Rate Topic: -----

#1 autoreverse  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 12

check from which checkedlistbox items are

Posted 01 December 2012 - 07:16 AM

I have two checkedListBoxes(checkedListBox1 and checkedListBox2) and one listBox1, where are items from both checkedListBoxes. I want to perform a check something like this:
 if listBox1.CheckedItem is from checkedListBox1 do...
    else if listBox1.CheckedItem is from checkedListBox2 do....


I have one button for passing items TO listBox and second one for passing values FROM listBox and i have trouble performing check from which checkedListBox items are.

I passed items to listBox like this:
string[] stringArray = new string[checkedListBox1.CheckedItems.Count];
listBox1.Items.AddRange(stringArray);


Of course with some checkings and cycles and same for other string[].

Is This A Good Question/Topic? 0
  • +

Replies To: check from which checkedlistbox items are

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5479
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: check from which checkedlistbox items are

Posted 01 December 2012 - 07:54 AM

You've told us what you want. But not shown us your actual code for giving it a try, or what error/problem you are encountering. We aren't going to write it for you.
Was This Post Helpful? 0
  • +
  • -

#3 autoreverse  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 12

Re: check from which checkedlistbox items are

Posted 01 December 2012 - 08:14 AM

I don't want you to do all work for me. I just want some hints and i'll figure it out.
I haven't actually tried something for this. I'm still in stage "figuring it out".
I can give you my code for 2 buttons:
This code for getting items TO listBox
public void button1_Click(object sender, EventArgs e)
        {
            
            if ((listBox1.Items.Count < 3) && (checkedListBox1.CheckedItems.Count > 0) && (checkedListBox1.CheckedItems.Count < 4))
            {
                
                string[] stringArray2 = new string[checkedListBox2.CheckedItems.Count];
                string[] stringArray = new string[checkedListBox1.CheckedItems.Count];
                checkedListBox1.CheckedItems.CopyTo(stringArray, 0);
                checkedListBox2.CheckedItems.CopyTo(stringArray2, 0);
                
                for (int i = 0; i < stringArray.Length; i++)
                {
                    checkedListBox1.Items.Remove(stringArray[i]);
                    
                }
                for (int i = 0; i < stringArray2.Length; i++)
                {
                    checkedListBox2.Items.Remove(stringArray2[i]);

                }

                listBox1.Items.AddRange(stringArray);
                listBox1.Items.AddRange(stringArray2);

            }

            else

                MessageBox.Show("Ludzu izvelaties 3 personas.");


        }


And this to get them back but for now only to checkedListBox1:
private void button2_Click(object sender, EventArgs e)
        {
          if (listBox1.SelectedItems.Count > 0 )
            {
                string[] stringArray3 = new string[listBox1.SelectedItems.Count];

                listBox1.SelectedItems.CopyTo(stringArray3, 0);

                for (int j = 0; j < stringArray3.Length; j++)
                {
                    listBox1.Items.Remove(stringArray3[j]);
                }

                checkedListBox1.Items.AddRange(stringArray3);
            }
           
            else
            {
                MessageBox.Show("Ludzu izvelaties vienu personu no laba loga");
            }
        }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1