VB.NET - getting the value sof ValueMember in checkedlistbox in windows forms

Asked By SVK N on 28-Oct-10 01:56 AM
in vb.net with windows forms  i have checkedlistbox populate with data from database
i have popolated it using dataset  and used displaymember="productname &

.ValueMember=productid


the names of products r displayed & when checked i  able to get the product name using  

checkedlistbox.CheckedItems(i).ToString.Trim  but how do i get the productid ???

Reena Jain replied to SVK N on 28-Oct-10 02:00 AM
hi,

use this
to get value
checkedlistbox.selectedValue.ToString();
to get item use this
checkedlistbox.selectedItem.ToString();


hope this will help you
SVK N replied to Reena Jain on 28-Oct-10 02:07 AM
i had used it but i am not gettin the right value & as multiple items are selected i have used it in loop
and checkedlistbox.selectedValue(i).ToString(); does seem to be working
Reena Jain replied to SVK N on 28-Oct-10 02:28 AM
hi,

try this

    foreach(DataRowView view in myCheckedList.CheckedItems)
    {
        string a=(view[myCheckedList.ValueMember].ToString());
    } 
hope this will help you
SVK N replied to Reena Jain on 28-Oct-10 05:49 AM

  For i As Integer = 0 To Me.checkedlistbox1.CheckedItems.Count - 1

 QRY= insert into products (customerid,productid)" _
               & " values (" & id.Text & ", '" &  checkedlistbox1.CheckedItems.Item(i)("productid") & "')"

next


by using above i get

Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

all the selected values are stored correctly as nnned but after the last product inserted  i get the above error

Jeremiah replied to Reena Jain on 17-Nov-10 10:44 PM
Cool! Thanks mate!

This is what I've been looking for too!