c# - vb.net动态设置gridview列的属性
问题描述
你好 StackOverFlow 家族
我的数据库中有一个表,其中包含已在 vb.net 应用程序表单上创建的所有网格视图的所有列,如下所示。
使用此表,我想控制我的应用程序中的每个 gridview,而不是手动在 vb.net 中添加列的属性,这意味着每次我想修改任何属性时,我都必须在应用程序级别进行并创建新的 exe 文件。
我的程序从上表(从数据库)中检索数据
我需要根据存储在此表中的数据动态修改列属性
提前致谢
解决方案
我可以给你一些例子。如果要更改整列的属性,可以这样做:
DataGridView1.Columns(0).DefaultCellStyle.BackColor = Color.Green
DataGridView1.Columns(0).DefaultCellStyle.ForeColor = Color.Yellow
如果要更改具有“TextToSearch”值的单元格的属性,可以这样做:
Dim x,y As Integer
For y = 0 to DataGridView1.Columns.Count - 1
For x = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(y).Cells(x).Value.ToString = "TextToSearch" Then
DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.Red
DataGridView1.Rows(y).Cells(x).Style.ForeColor = Color.White
End If
Next
Next
推荐阅读
- javascript - Vega Charts 抛出类型定义错误
- vba - 用于创建多个 PDF 的 VBA
- python - 根据 groupby 之后其他列中的值之间的数据框范围对单独的列进行求和
- javascript - 后端python烧瓶代码不返回对前端ajax代码的否定响应,它只返回成功响应
- curl - 无法使用 Octave(4.4.1) 提交在线作业
- socket.io - 从 ID 获取套接字对象
- angular - 调用 signalR 失败
- c++ - 如何阻止空格键触发聚焦的 QPushButton?
- selenium - 如何为具有大量变量的情况构建 BDD 场景
- c - 有没有办法使用 libcurl >=7.3.x 从 HTTP 标头中获取内容长度?