【发布时间】:2013-10-02 09:02:29
【问题描述】:
我在 gridview 中选择所有带有后续代码的行
gridView1.SelectAll();
现在我想在 gridview 中为选定的行着色,例如蓝色。
我该怎么做?
【问题讨论】:
标签: c# winforms gridview devexpress xtragrid
我在 gridview 中选择所有带有后续代码的行
gridView1.SelectAll();
现在我想在 gridview 中为选定的行着色,例如蓝色。
我该怎么做?
【问题讨论】:
标签: c# winforms gridview devexpress xtragrid
我相信你说的是DevExpress XtraGrid。如果是这样,那么根据您的特定任务,有多种方法可以突出显示 DevExpress XtraGrid 中的特定行。 例如,要突出显示任何选定的行,您可以使用以下代码:
gridView1.Appearance.SelectedRow.BackColor = Color.Red;
要使用自定义条件突出显示特定行,您可以使用 GridView.RowStyle 事件:
void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) {
if((e.State & DevExpress.XtraGrid.Views.Base.GridRowCellState.Selected) != 0) {
// check some conditions
e.HighPriority = true;
e.Appearance.BackColor = Color.Blue;
}
}
请在以下帮助文章中阅读有关所有这些方法的更多信息:Customizing Appearances of Individual Rows and Cells
【讨论】:
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
row.DefaultCellStyle.BackColor = Color.Blue;
}
【讨论】:
您可以使用 SelectedRowStyle 属性
【讨论】:
试试这个,
To change selected rows
private void button1_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.SelectedRows)
{
if (null != item)
{
item.DefaultCellStyle.BackColor = Color.Blue;
}
}
}
To change all rows
foreach (DataGridViewRow item in dataGridView1.Rows)
{
}
【讨论】:
对于gridview,为事件CellFormatting设置下面的方法
private void StocksDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
StocksDataGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.OrangeRed;
}
【讨论】: