Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
Hi @Martin Nikodijevic ,
Create a global variable that records the currently selected row and column indexes, and restores the previous selected state of the cell when the DataGridView is refreshed during the timer tick event.
For example:
int selectedRowIndex = -1;
int selectedColumnIndex = -1;
private void RecordSelectedCell()
{
if (dataGridView1.SelectedCells.Count > 0)
{
selectedRowIndex = dataGridView1.SelectedCells[0].RowIndex;
selectedColumnIndex = dataGridView1.SelectedCells[0].ColumnIndex;
}
else
{
selectedRowIndex = -1;
selectedColumnIndex = -1;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
RecordSelectedCell();
if (selectedRowIndex >= 0 && selectedColumnIndex >= 0 &&
selectedRowIndex < dataGridView1.Rows.Count &&
selectedColumnIndex < dataGridView1.Columns.Count)
{
dataGridView1.ClearSelection();
dataGridView1.Rows[selectedRowIndex].Cells[selectedColumnIndex].Selected = true;
}
}
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.