2014-02-17 35 views

回答

3

首先,你必須找到包含行今天的日期:

int dateColumnIndex = DataGridView1.Columns["e_date"].Index;// < replace with your actual date column name 
foreach (DataGridViewRow row in DataGridView1.Rows) 
{ 
    if (row.Cells[dateColumnIndex].Value is DateTime) 
    { 
     DateTime colDate = (DateTime)row.Cells[dateColumnIndex].Value; 
     if (colDate.Date == DateTime.Today) 
     { 
      row.Selected = true; 
      break; 
     } 
    }     
} 

只要確保你的DataGridViewselection mode設置爲FullRowSelect

dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

+0

int dateColumnIndex = DataGridView1.Columns.IndexOf(「Date-Column-Name」);我修改了上述行..... int dateColumnIndex = dataGridView1.Columns.IndexOf(「e_date」)....即時通訊錯誤..無效論據 – Brian

+0

@Brian我不明白你的意見。 –

+0

我已經編輯了評論請看看 – Brian

-1

的想法是,循環顯示您的結果列表以獲得您希望亮起的那些行,並將selectedRow設置如下:

myDataGrid.Rows[n].IsSelected = true; 
相關問題