hi everyone,
I am populating a Checkedlistbox "lstExpert" from table "TableA" succesfully.
Whenever an item is checked in the Checkedlistbox "lstExpert", i am saving it into another table "GroupExpert".
For some reason i am using a recordset to save the data into an sql table.
Now what i am stuck is HOW TO RETAIN the CHECKSTATE of the Checkedlistbox "lstExpert" meaning even when i close the from and re-open it, the names that were selected and saved in Table "GroupExpert " should remain checked.
I tried the following code but no success so far.
Is it the right way to do by comparing index in Checkedlistbox "lstExpert" and "Listbox1"
Is there a way to bind it directly to the table "GroupExpert" meaning if the value of the Checkedlistbox "lstExpert" is present in the "GroupExpert" then the item will be cheked... I tried the following code and nothing seems to work.....
Any suggestions....
Thanx and Cheers
irfi
I am populating a Checkedlistbox "lstExpert" from table "TableA" succesfully.
Whenever an item is checked in the Checkedlistbox "lstExpert", i am saving it into another table "GroupExpert".
For some reason i am using a recordset to save the data into an sql table.
VB.NET:
' For saving data into sql table when an item is checked
Dim i As Integer
Dim rsgroup As New ADODB.Recordset
Dim qry As String
qry = "Select * from GroupExpert where ID=" & Label9.Text
rsgroup.Open(Qry, db, ADODB.CursorTypeEnum.adOpenDynamic,ADODB.LockTypeEnum.adLockOptimistic)
For i = 0 To lstExpert.Items.Count - 1
If lstExpert.GetSelected(i) = True Then
rsgroup.AddNew()
rsgroup.Fields("ID").Value = Label9.Text
rsgroup.Fields("ExpertName").Value = lstExpert.Items.Item(i)
rsgroup.UpdateBatch(ADODB.AffectEnum.adAffectAll)
End If
Next
rsgroup.Close()
Call fillgrouplistbox() ' To show saved names in Table "GroupExpert" into another listobx called "Listbox1"
Now what i am stuck is HOW TO RETAIN the CHECKSTATE of the Checkedlistbox "lstExpert" meaning even when i close the from and re-open it, the names that were selected and saved in Table "GroupExpert " should remain checked.
I tried the following code but no success so far.
VB.NET:
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
lstExpert.SetItemCheckState((lstExpert.Items.IndexOf(ListBox1.SelectedItems.Item(i))), CheckState.Checked)
Next
Is it the right way to do by comparing index in Checkedlistbox "lstExpert" and "Listbox1"
Is there a way to bind it directly to the table "GroupExpert" meaning if the value of the Checkedlistbox "lstExpert" is present in the "GroupExpert" then the item will be cheked... I tried the following code and nothing seems to work.....
VB.NET:
For i As Integer = 0 To Me.lstExpert.Items.Count - 1
For j As Integer = 0 To rsgroup.GetRows.Rows.Count - 1
If Me.lstExpert.Items.Item(i).item(0) = rsgroup.GetRows.Rows(j).Item(0) Then
Me.lstExpert.SetItemChecked(i, True)
End If
Next
Next
Any suggestions....
Thanx and Cheers
irfi