Thank you for your response. I have updated my code, but it is showing an error message after the solution build is run. The error is System.OutOfMemoryException: 'List box contains too many items.' I searched on Google for this error and it seem to do with the GetString() returns an item which has a null value. I am not sure how to fix the issue. I hope that you can assist me with this issue. My code is:
Operation.vb (class)
CheckedListItem.vb (class)Code:Public Function LoadData() As List(Of CheckListBoxItem) Dim itemList = New List(Of CheckListBoxItem) Using cn As MySqlConnection = New MySqlConnection With {.ConnectionString = ConnectionString} Using cmd As New MySqlCommand("SELECT OrderID, ProductID, Orders, CheckedStatus,FROM Store.Orders", cn) cmd.CommandText = <SQL> SELECT OrderID, ProductID, Orders, CheckedStatus FROM Orders; </SQL>.Value Dim dt As New DataTable With {.TableName = "Orderss"} cn.Open() Dim reader = cmd.ExecuteReader() If reader.HasRows Then While reader.Read itemList.Add(New CheckListBoxItem With { .OrderID = reader.GetInt32(0), .ProductID = reader.GetInt32(1), .Orders = reader.GetString(2), .CheckedStatus = reader.GetBoolean(3) }) End While End If reader.Close() End Using End Using Return itemList End Function
Form1.vbCode:Public Class CheckListBoxItem ''' <summary> ''' Identifier for database table ''' </summary> Public PrimaryKey As Integer ''' <summary> ''' Display member for CheckedListBox and a field in the table ''' </summary> Public Property OrderID As Integer Public Property Item As String Public Property ProductID As Integer Public Property Orders As String Public Property CheckedStatus As Boolean Public Property Quantity As String Public Property ColumnName As String Public Property Checked As Boolean ''' <summary> ''' Used to determine if a item changed after loaded in the CheckedListBox ''' </summary> Public IsDirty As Boolean Public Overrides Function ToString() As String Return Item Return String.Empty End Function End Class
Thank you in advance for your assistance.Code:Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Load Dim ops = New Operations() ' read data from database table Dim Items = ops.LoadData() Dim LastIndex As Integer = 0 For Each item As CheckListBoxItem In Items CheckedListBox1.Items.Add(item) LastIndex = CheckedListBox1.Items.Count - 1 CheckedListBox1.SetItemChecked(LastIndex, item.Checked) Next AddHandler CheckedListBox1.ItemCheck, AddressOf CheckedListBox1_ItemCheck




Reply With Quote
