我一直试图弄清楚如何清除和重绘DataGridView。但到目前为止,我已经得到了相同的结果,数据只是继续写入并在刷新时写入自身,导致冗余记录。
这是我的代码:
DataGridView1.DataSource = Nothing
DataGridView1.DataMember = Nothing
DataGridView1.Columns.Clear()
DataGridView1.Rows.Clear()
SQLSTR = "SELECT * FROM '" & ClassIntl & "'"
DBConn()
SQLDA.Fill(DS, "Grades")
SQLCONN.Close()
DataGridView1.DataSource = DS
DataGridView1.DataMember = "Grades"
With DataGridView1
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Student ID"
.Columns(1).HeaderCell.Value = "First Name"
.Columns(2).HeaderCell.Value = "Last Name"
.Columns(3).HeaderCell.Value = "Quiz 1"
.Columns(4).HeaderCell.Value = "Quiz 2"
.Columns(5).HeaderCell.Value = "Quiz 3"
.Columns(6).HeaderCell.Value = "Quiz 4"
.Columns(7).HeaderCell.Value = "Quiz 5"
.Columns(8).HeaderCell.Value = "Quiz 6"
.Columns(9).HeaderCell.Value = "CS Prelim"
.Columns(10).HeaderCell.Value = "CS Midterm"
.Columns(11).HeaderCell.Value = "CS Finals"
.Columns(12).HeaderCell.Value = "Attend Prelim"
.Columns(13).HeaderCell.Value = "Attend Midterm"
.Columns(14).HeaderCell.Value = "Attend Finals"
.Columns(15).HeaderCell.Value = "Exam Prelim"
.Columns(16).HeaderCell.Value = "Exam Midterm"
.Columns(17).HeaderCell.Value = "Exam Finals"
.Columns(18).HeaderCell.Value = "Total Prelim"
.Columns(19).HeaderCell.Value = "Total Midterm"
.Columns(20).HeaderCell.Value = "Total Finals"
.Columns(21).HeaderCell.Value = "Final Grade"
End With
建议会很棒,谢谢!
答案 0 :(得分:0)
您可以将DataGridView绑定为null。它会工作: DataGridView1.DataSource = null;