Get Value From CheckedListBox

Hi ,

I'm need to get values for all the checked Items. regretfully, I'm getting
every time the value of the last cheked Item.

//Populate Data Into myClb

strQuery = "SELECT code,title FROM tbl1"

orclDa =
new OracleDataAdapter(strQuery, strOrclConn);

orclDa.Fill(orclDs, "tbl1");

myClb.DataSource = orclDs.Tables["tbl1"];

myClb.DisplayMember = "title";

myCld.ValueMember = "code";

myClb.SelectedIndex = -1;

// Start Checking

foreach
(object itemChecked in clbMifalim.CheckedItems)
{
MessageBox
.Show(" Value is:" + clbMifalim.SelectedValue.ToString() + ".");
}

Please Help
Regards Boaz.



Answer this question

Get Value From CheckedListBox

  • GoPrior

    Now I get :

    value is : "System.Data.DataRowView"

    Thanks Anyway,
    BOAZ.


  • dinks

    I just ran into this issue and I just used the following to grab from the chec

    foreach (DataRowView row in checkedlistbox.CheckedItems)

    {

    MessageBox.Show(row["<DisplayMember>"].ToString());

    // Or use the index of your datatable your looking for.

    MessageBox.Show(row[1].ToString());

    }


  • ThomasFreudenberg

    foreach (int i in myList.SelectedIndices)

    {

    DataRowView drv = (DataRowView)myList.ItemsIdea;

    myStr = drv.Row[lstMifalim.ValueMember].ToString();

    MessageBox.Show(myStr);

    }


    Enjoy.


  • Kaliko

    It's still returns the index of all the checked values , but what I need is the "Title" of them ( I'm meaning to the DisplayMember).

    Tahnks anyway,
    Boaz.

  • paulmig

    Boaz Shalev wrote:
    FIX THE CODE:

    foreach (int i in myList.SelectedIndices)

    {

    DataRowView drv = (DataRowView)myList.Items;

    myStr = drv.Row[myList.ValueMember].ToString();

    MessageBox.Show(myStr);

    }


    Enjoy.


    hi Boaz, i tried with your code. but there is one small problem.
    then i have 2 items selected in the checkedlistbox, the messagebox will keep showing the first selected item.
    that means if i have 4 items in clb and 2 are selected, the msgbox will be showed twice.

  • SQL2005usr

    Use the CheckedListBox.SelectedItems collection to iterate through the selected items and then retrieve the corresponding property
  • Leonardo Carlos Prada

    This is the code that I used to get the Values of the Selected items.. I am not getting the Index, I am getting the actual values



    foreach (object itemChecked in clbMifalim.CheckedItems)
    {
       MessageBox.Show(" Value is:" + itemChecked.ToString() + ".");
    }

     


  • Gazeth

     FIX THE CODE:

    foreach (int i in myList.SelectedIndices)

    {

    DataRowView drv = (DataRowView)myList.ItemsIdea;

    myStr = drv.Row[myList.ValueMember].ToString();

    MessageBox.Show(myStr);

    }


    Enjoy.


  • Aamir Iqbal


    Change this Statement
    MessageBox.Show(" Value is:" + clbMifalim.SelectedValue.ToString() + ".");
    TO
    MessageBox.Show(" Value is:" + itemChecked.ToString() + ".");

    The reason Why it is showing the last item is that you are not using itemChecked object to get the value, instead you are using the Listbox itself..

  • Get Value From CheckedListBox