newguy
Well-known member
Hi all, I have a checkedlistbox, and I want to have the value for each checked box to sent to a textbox.
So I basically want the "1", "2" or "3" to show up in the textbox the cooresponding checkbox checked.
But I keep getting a InvalidCastException - unable to cast object of type system.eventArgs to system.windows.form.itemsCheckedArgs.
Any ideas?
VB.NET:
Public Class Form1
Dim chklistbox1 As New BetterCheckedListBox
Public Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Select Case ListBox1.SelectedIndex
Case 0
GroupBox1.Controls.Clear()
GroupBox2.Controls.Clear()
With chklistbox1
.BackColor = Color.LightBlue
.Dock = DockStyle.Fill
.ThreeDCheckBoxes = True
.Sorted = False
.BorderStyle = BorderStyle.Fixed3D
.CheckOnClick = True
.Items.Add("1", False)
.Items.Add("2", False)
.Items.Add("3", False)
End With
GroupBox2.Controls.Add(chklistbox1)
AddHandler chklistbox1.ItemCheck, AddressOf chklistbox1_itemCheck
End Select
End Sub
Private Sub chklistbox1_itemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs)
Dim itm As String = chklistbox1.SelectedItem
If e.NewValue = CheckState.Checked Then
Comments.Text = itm
Else
If e.NewValue = CheckState.Unchecked Then
Comments.Text = ""
End If
End If
End Sub
End Class
So I basically want the "1", "2" or "3" to show up in the textbox the cooresponding checkbox checked.
But I keep getting a InvalidCastException - unable to cast object of type system.eventArgs to system.windows.form.itemsCheckedArgs.
Any ideas?