+ Reply to Thread
Results 1 to 2 of 2

Thread: how to get checked item text and value

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    how to get checked item text and value

    I have used a CheckedListBox over my WinForm in C#. I have bounded this control as shown below -
    Code:
    chlCompanies.DataSource = dsCompanies.Tables[0];
    chlCompanies.DisplayMember = "CompanyName";
    chlCompanies.ValueMember = "ID";
    I can get the indices of checked items, but how can i get checked item text and value. Rather how can i enumerate through CheckedItems accessing Text and Value?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    14
    Cast it back to its original type, which will be a DataRowView if you're binding a table, and you can then get the Id and Text from the appropriate columns:
    Code:
    foreach(object itemChecked in checkedListBox1.CheckedItems)
    {
         DataRowView castedItem = itemChecked as DataRowView;
         string comapnyName = castedItem["CompanyName"];
         int? id = castedItem["ID"];
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts