so I imported an already made Windows Form with Listview and other controls from Windows Form. I connected the Form to MySQL and it works fine but Im having a problem with my Listview. Heres the code:
Dim MysqlConn As MySqlConnection
Dim MysqlCmd As MySqlCommand
Dim strQuery As String
Dim MysqlDR As MySqlDataReader
Try
lstStudent.Items.Clear()
If SubjNo = 0 Then
cboSubj.Text = "There are no subjects recorded."
txtDesc.Text = "---"
txtSched.Text = "---"
txtSearch.Enabled = False
Else
txtSearch.Enabled = True
'LISTVIEW
Try
strQuery = "SELECT * FROM thesis_db.std_records WHERE ProfIDNo=" & lstProfID.SelectedItem & " AND SubjectNo=" & SubjNo & " order by Student_LName"
MysqlCmd = New MySqlCommand(strQuery, MysqlConn)
MysqlDR = MysqlCmd.ExecuteReader
Dim arr(3) As String
Dim itm As ListViewItem
While MysqlDR.Read
arr(0) = MysqlDR.Item("Student_LName").ToString
arr(1) = MysqlDR.Item("Student_FName").ToString
arr(2) = MysqlDR.Item("Student_MI").ToString
arr(3) = MysqlDR.Item("Score").ToString
itm = New ListViewItem(arr)
lstStudent.Items.Add(itm)
End While
MysqlDR.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
MysqlDR.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
The First code with error:
itm = New ListViewItem(arr)
The underlined word: arr
The Error: Too many arguments to 'Public Sub New()'.
The Second code with error:
lstStudent.Items.Add(itm)
The whole line is underlined.
The Error: Overload resolution failed because no accessible 'Add' can be called with these arguments: 'Public Overridable Function Add(value As System.Windows.Forms.ListViewItem) As System.Windows.Forms.ListViewItem': Value of type 'System.Windows.Controls.ListViewItem' cannot be converted to 'System.Windows.Forms.ListViewItem'. 'Public Overridable Function Add(text As String) As System.Windows.Forms.ListViewItem': Value of type 'System.Windows.Controls.ListViewItem' cannot be converted to 'String'.
Aucun commentaire:
Enregistrer un commentaire