我正在使用vb.net中的DataGridView,並試圖將在DataGridView中所做的更改保存到我的Access數據庫中。問題是,用戶可以通過選擇他們想要的任何單元格然後更改顏色來更改單個單元格的背景顏色。我無法弄清楚如何保存單個單元格背景顏色,以便在程序再次運行時顯示顏色。當用戶點擊保存時,顏色格式被擦除。我也不認爲我可以通過添加顏色列在Access的Access端執行此操作,因爲每行和每列都會使用多種顏色。有沒有辦法保存單元格樣式格式?這裏是代碼... 這是保存按鈕如何將DataGridView單元格樣式保存到數據庫
Private Sub DsfToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles DsfToolStripMenuItem.Click
BaggersTableAdapter.Update(RentalsDataSet.Tables(0))
RentalsDataSet.Tables(0).AcceptChanges()
End Sub
那就是點擊更改所選單元格的顏色的按鈕。
Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
For i As Integer = 0 To DataGridView1.SelectedCells.Count - 1
'Dim a As String = (DataGridView1.SelectedCells(i).RowIndex.ToString)
Dim colIndex As Integer = DataGridView1.SelectedCells(i).ColumnIndex
Dim rowIndex As Integer = DataGridView1.SelectedCells(i).RowIndex
DataGridView1.Item(colIndex, rowIndex).Style.BackColor = Color.LightGreen
Next
End Sub