如何将DataGridView单元格样式保存到数据库
问题描述:
我正在使用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
答
我会创建表来保存设计颜色。喜欢的东西 grid_style_header(header_id,grid_id,USER_ID) grid_style_cells(ID,header_id,行,列,颜色)...如果你允许电网的过滤
的问题可能发生。如果发生这种情况,您的列可能会保留,但行可能不会或他们可能上移或下移。
更好的解决方案,如果你能实现它:grid_style_cells(ID,header_id,row_guid(在你的数据库ID无论主键),列名,色)
这使得该行标识符绝对的,所以你没有任何过滤问题。列名也摆脱列重写问题。
我不知道任何内置解决方案。