Jas*_*ore 19
为了模拟用户选择一行,请使用
myDataGrid.Rows[n].IsSelected = true;
Run Code Online (Sandbox Code Playgroud)
正如加布里埃尔所说的那样.
为了在DataGridView控件中临时突出显示DefaultCellStyle.BackColor颜色,请将该属性设置为您感兴趣的行所选择的颜色.然后System.Windows.Forms.Timer为您选择的时间段启用控件.当计时器的Tick事件触发时,禁用计时器并将行设置DefaultCellStyle.BackColor回原始颜色.
下面的简短示例适用于WinForm应用程序,该应用程序具有名为GlowDataGrid的DataGridView,名为GlowTimer的计时器和名为GlowButton的按钮.单击GlowButton时,DataGridView的第三行暂时呈现黄色两秒钟.
private void Form1_Load(object sender, EventArgs e)
{
// initialize datagrid with some values
GlowDataGrid.Rows.Add(5);
string[] names = new string[] { "Mary","James","Michael","Linda","Susan"};
for(int i = 0; i < 5; i++)
{
GlowDataGrid[0, i].Value = names[i];
GlowDataGrid[1, i].Value = i;
}
}
private void GlowButton_Click(object sender, EventArgs e)
{
// set third row's back color to yellow
GlowDataGrid.Rows[2].DefaultCellStyle.BackColor = Color.Yellow;
// set glow interval to 2000 milliseconds
GlowTimer.Interval = 2000;
GlowTimer.Enabled = true;
}
private void GlowTimer_Tick(object sender, EventArgs e)
{
// disable timer and set the color back to white
GlowTimer.Enabled = false;
GlowDataGrid.Rows[2].DefaultCellStyle.BackColor = Color.White;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40621 次 |
| 最近记录: |