本文介绍了将背景颜色更改为行网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格视图,我想要点击哪一行将其背景颜色更改为红色。但我有一个问题,我点击一行,颜色变为红色,然后当我点击一个不同的行时,它也改变了它的背面颜色,但预览一个保持红色。我希望唯一选择的行为红色。

我的代码如下:



I have a grid view, and I want that which row i click to change its background color to red. but I have a problem, i click a row and the color changes to red, then when i click a different row it also changes its back color but the previews one stays red. I want that the only selected row to be red.
my code looks like this:

i = MyGrd.SelectedCells(0).RowIndex
MyGrd.Rows(i).DefaultCellStyle.BackColor = Color.Red

推荐答案

Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
    For Each row As GridViewRow In GridView1.Rows
        If row.RowIndex = GridView1.SelectedIndex Then
            row.BackColor = ColorTranslator.FromHtml("#A1DCF2")
        Else
            row.BackColor = ColorTranslator.FromHtml("#FFFFFF")
        End If
    Next
End Sub


这篇关于将背景颜色更改为行网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:50
查看更多