C# APP "CheckedListBox to array"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sql2020
    New Member
    • Dec 2008
    • 6

    #1

    C# APP "CheckedListBox to array"

    Hi, i am fresh grad and having some problems. the problems as below and iIt is quiet urgent.........

    i have two CheckedListBox (CLBa and CLBb) , and i want the user selected CheckedListBox is assign to two dimension array.

    Objective:
    There is a sql statement (select * from tblname where field1= ' ' OR field2=' '),
    i want to allow user to choose the data for filetring,

    where
    - field1 will read selected item in CLBa
    - field2 will read selected item in CLBb
    - the sql statement is use for 1 table only

    possibility
    - single row might have selected data in field1 and field2
    - row is not duplicated in the result of select statement

    solution
    - i plan to assign the selected item in CLBa and CLBb to a two dimensional array
    - from the array i read the data and filter

    problem
    - how to assign the selected in both check box list to an two dimension array?



    Thank you
  • Ramk
    New Member
    • Nov 2008
    • 61

    #2
    Try using this with jagged array. It loops the number of items selected in CLBa checkedlistbox.
    my2DArray[row][0] -> Will fetch the CLBa object.
    my2DArray[row][1] -> Will fetch the CLBb object.

    Code:
     
    private void button1_Click(object sender, EventArgs e)
            {
                CheckedListBox.CheckedItemCollection si1 = checkedListBox1.CheckedItems;
                CheckedListBox.CheckedItemCollection si2 = checkedListBox2.CheckedItems;
                Object[][] my2DArray = new Object[si1.Count][];
                int row = 0, it2=0;
                int obj2Cnt = si2.Count;
                foreach (Object s1 in si1)
                {
                    Object s2 = new Object();
     
                    if (it2 < obj2Cnt)
                    {
                        s2 = si2[it2];
                        it2++;
                    }
                    my2DArray[row] = new Object[2] { s1, s2 };
                    row++;
                }
            }

    Comment

    Working...