Как выбрать или сфокусироваться на колонке в зависимости от времени суток
Я импортировал электронную таблицу (заголовки столбцов помечены как время, с шагом 30 минут с 9: 00 до 8: 30) в datagridview на winform. Я хочу сфокусировать и выделить (автоматическая прокрутка или выбор столбца) столбец в зависимости от времени суток. Как я могу это сделать? Заранее спасибо.
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; namespace lowcp { public partial class Form1 : Form { public Form1() { InitializeComponent(); System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer(); timer1.Interval = 1000; timer1.Tick += new System.EventHandler(timer1_Tick); timer1.Start(); TimeLabel.Text = DateTime.Now.ToLongTimeString();//TIME DateLabel.Text = DateTime.Now.ToLongDateString();// DATE OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\CooksProjection\CProjection.xls" + ";Extended Properties=" + "\"Excel 12.0 Xml;HDR=YES;IMEX=1\""; OleDbCommand command = new OleDbCommand ("SELECT * FROM [Display$]", conn); DataSet Form1 = new DataSet(); OleDbDataAdapter adapter = new OleDbDataAdapter(command); adapter.Fill(Form1); dataGridView1.DataSource = CPP.Tables["Display$"]; dataGridView1.RowsDefaultCellStyle.BackColor = Color.PaleVioletRed; dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White; dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; FreezeBand(dataGridView1.Columns["Prep"]); } private void Form1_Load(object sender, EventArgs e) { } private static void FreezeBand(DataGridViewBand band) { band.Frozen = true; DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.WhiteSmoke; band.DefaultCellStyle = style; } private void label1_Click(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { TimeLabel.Text = DateTime.Now.ToLongTimeString(); timer1.Start(); } private void TimeLabel_Click(object sender, EventArgs e) { } private void timenow(object sender, ScrollEventArgs e) { } } }