Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c中为GridView中选定的行着色#_C#_Winforms_Gridview_Devexpress_Xtragrid - Fatal编程技术网

C# 如何在c中为GridView中选定的行着色#

C# 如何在c中为GridView中选定的行着色#,c#,winforms,gridview,devexpress,xtragrid,C#,Winforms,Gridview,Devexpress,Xtragrid,我在gridview中选择包含以下代码的所有行 gridView1.SelectAll() 现在我想给gridview中选定的行上色,例如蓝色 如何操作?您可以使用SelectedRowStyle属性 foreach (DataGridViewRow row in dataGridView1.SelectedRows) { row.DefaultCellStyle.BackColor = Color.Blue; } 试试这个 更改所选行 private void button1_Cli

我在gridview中选择包含以下代码的所有行

gridView1.SelectAll()

现在我想给gridview中选定的行上色,例如蓝色


如何操作?

您可以使用SelectedRowStyle属性

foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
    row.DefaultCellStyle.BackColor = Color.Blue;
}
试试这个

更改所选行

private void button1_Click(object sender, EventArgs e)
    {
        foreach (DataGridViewRow item in dataGridView1.SelectedRows)
        {
            if (null != item)
            {
                item.DefaultCellStyle.BackColor = Color.Blue;
            }
        }            
    }
foreach (DataGridViewRow item in dataGridView1.Rows)
{
}
更改所有行

private void button1_Click(object sender, EventArgs e)
    {
        foreach (DataGridViewRow item in dataGridView1.SelectedRows)
        {
            if (null != item)
            {
                item.DefaultCellStyle.BackColor = Color.Blue;
            }
        }            
    }
foreach (DataGridViewRow item in dataGridView1.Rows)
{
}

我相信你是在谈论这个问题。如果是这样,则有多种方法可以突出显示DevExpress XtraGrid中的特定行,具体取决于您的特定任务。 例如,要高亮显示任何选定行,可以使用以下代码:

gridView1.Appearance.SelectedRow.BackColor = Color.Red;
要使用自定义条件高亮显示特定行,可以使用事件:


请在下面的帮助文章中阅读有关所有这些方法的更多信息:

对于gridview,请设置以下事件格式设置方法

private void StocksDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
    StocksDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.OrangeRed;
}

您说过您使用了
DevexpressGrid
。因此,通过在设计时更改
girdView的属性
,可以很容易地实现这一点


我使用DevExpress GridViewoops。你没有提到。:)