回答
您可以通過突出「N」行someDataGridView.Rows [n] .IsSelected = true;
您可以使用GridView
AutoFormat
屬性。
爲了模擬用戶選擇某一行,使用
myDataGrid.Rows[n].IsSelected = true;
如加布裏埃爾曾建議。
爲了暫時的顏色突出一個DataGridView控件中的行,設置DefaultCellStyle.BackColor
屬性爲您選擇您感興趣的行的顏色,然後啓用System.Windows.Forms.Timer
控制供你選擇的時間段。當計時器的Tick
事件觸發時,禁用計時器並將行的DefaultCellStyle.BackColor
恢復爲其原始顏色。
下面的簡短示例是針對具有名爲GlowDataGrid的DataGridView,名爲GlowTimer的計時器和名爲GlowButton的按鈕的WinForm應用程序。當點擊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;
}
應該被選中而不是被選中 – eYe 2015-03-17 15:26:03
我的代碼,你
private void Form1_Load(object sender, EventArgs e)
{
Timer t = new Timer();
t.Interval = 500;
t.Enabled = false;
dataGridView1.CellMouseEnter += (a, b) =>
{
if (b.RowIndex != -1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[b.RowIndex].Cells[0];
dataGridView1.Rows[b.RowIndex].DefaultCellStyle.SelectionBackColor = Color.Yellow;
dataGridView1.Rows[b.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Black;
t.Tick += (c, d) =>
{
dataGridView1.Rows[b.RowIndex].DefaultCellStyle.SelectionBackColor = Color.Blue;
dataGridView1.Rows[b.RowIndex].DefaultCellStyle.SelectionForeColor = Color.White;
t.Enabled = false;
};
t.Enabled = true;
}
};
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.Columns.Add("Col1", "Col1");
dataGridView1.Columns.Add("Col2", "Col2");
dataGridView1.Rows.Add("Row1", "Col1");
dataGridView1.Rows.Add("Row1", "Col2");
dataGridView1.Rows.Add("Row2", "Col1");
dataGridView1.Rows.Add("Row2", "Col2");
dataGridView1.Rows.Add("Row3", "Col1");
dataGridView1.Rows.Add("Row3", "Col2");
dataGridView1.Rows.Add("Row4", "Col1");
dataGridView1.Rows.Add("Row4", "Col2");
}
你有沒有得到你的答案。如果是,請分享它,它可能會幫助其他人 – 2011-04-21 01:24:49
使用像
gridLibrary.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
設置顏色,那麼你將需要 電網排序後重置顏色。
然後使用計時器在延遲後更改高光顏色。
gridLibrary.Rows(i).DefaultCellStyle.BackColor = Color.white
(i)應該是[i] C#問題 – David 2016-07-07 15:26:34
- 1. 突出顯示DataGridView行
- 2. 如何使用RowFilter將行突出顯示在datagridview中?
- 3. DataGridView - 突出顯示有晚項的行
- 4. 無法突出顯示DataGridView中的行
- 5. 如何突出顯示Xcode光標?
- 6. 如何使用ReactJS暫時突出顯示股票行情價值變化?
- 7. Flex TextArea - 如何突出顯示光標下的行/行?
- 8. 如何更改DataGridView中所有突出顯示的行 - VB.NEt
- 9. C#/ .NET如何突出顯示DataGridView中的某些行
- 10. 如何突出顯示datagridview中的整行數據?
- 11. Silverlight 3 Datagrid - 暫時突出顯示一行
- 12. 如何正確突出顯示VIM中的光標行?
- 13. 單擊時突出顯示一個光滑的行
- 14. 如何在搜索文本框中輸入字符時突出顯示datagridview行
- 15. 如何在突出顯示時使用突出顯示縮進代碼highlight.js
- 16. 突出顯示DataGridView中的單詞?
- 17. 目標C:如何突出顯示tableView單元格,並在表格重新加載時使其突出顯示?
- 18. VIM不突出顯示PHP文件,突出顯示其他人
- 19. 突出顯示ST2中的光標列
- 20. 突出顯示td或tr
- 21. 如何在DataGridView中單擊按鈕時未顯示其他行?
- 22. jquery突出顯示一個鏈接或刪除突出顯示
- 23. 如何突出顯示IsSelected的行
- 24. 如何突出顯示時間範圍?
- 25. 如何突出顯示DataGridView中的搜索文本?
- 26. 如何使DataGridView顯示選定的行?
- 27. recyclerview,單擊突出顯示並使其他人不突出
- 28. 如何突出或改變一個DataGridView行
- 29. 如何突出顯示UITableViewCell
- 30. 如何通過XtraGrid上的邊框突出顯示突出顯示的行
暫時在本地,當您選擇該行或默認情況下。 – 2011-04-13 07:53:42
你可以通過selectedrowstyle爲網格做1,但你打算通過**發光行暫時** ** – V4Vendetta 2011-04-13 07:59:07
@克雷格,你忘了說**現在**。我看到你在我以前的評論後接受了9個答案。 – 2011-04-19 09:35:43