本文介绍了如何在windows form vb.net程序的datagridview中更改整列的backcolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我希望找到一种简单的方法来更改datagridview中整个列的背景颜色。我的程序是一个Windows窗体vb.net程序。这是我到目前为止,但它似乎没有工作。
datagridview1.columns(0).defaultcellstyle.backcolor = color.blue
我非常感谢您提供的任何帮助或建议。谢谢!
Hello I'm hoping to find an easy way to change the backcolor for an entire column in a datagridview. My program is a windows forms vb.net program. This is what I have so far but it doesn't seem to be working.
datagridview1.columns(0).defaultcellstyle.backcolor = color.blue
I greatly appreciate any help or suggestions you may offer. Thanks!
推荐答案
Using con As New SqlConnection(strConnect)
con.Open()
Dim dt As New DataTable()
Dim da As New SqlDataAdapter("SELECT * FROM MyTable", con)
da.Fill(dt)
myDataGridView.DataSource = dt
myDataGridView.Columns(0).DefaultCellStyle.BackColor = Color.Blue
End Using
我在做什么不同于你?
What am I doing that is different from you?
Private Sub dgvfamily_CellLeave(sender As Object, e As DataGridViewCellEventArgs)
For i As Integer = 0 To dgvfamily.Rows.Count - 1
'dgvfamily.Rows[i].Cells[0].Value = (i + 1).ToString();
For j As Integer = 1 To dgvfamily.Columns.Count - 1
If dgvfamily.Rows(i).Cells(j).Value Is Nothing Then
'dgvfamily.ClearSelection();
dgvfamily.Rows(i).Cells(j).Style.BackColor = Color.RoyalBlue
dgvfamily.CurrentCell = dgvfamily.Rows(i).Cells(j)
Return
End If
Next
Next
我使用这个当datagrid单元格留空时,它会改变空白单元格的颜色
谢谢
Kishan
这篇关于如何在windows form vb.net程序的datagridview中更改整列的backcolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!