Torna al Thread
private void CreateButton2(DateTime _inizio, DataTable tabella)
{
this.groupBox1.Controls.Clear();
List<DateTime> _dtTodb = new List<DateTime>();
foreach (DataRow riga in tabella.Rows)
{
if (!_dtTodb.Contains(Convert.ToDateTime(riga["inizio"])))
{
_dtTodb.Add(Convert.ToDateTime(riga["inizio"]));
}
}
try
{
Dictionary<DateTime, Button> btnTime = new Dictionary<DateTime, Button>();
DateTime startTime = new DateTime(_inizio.Year, _inizio.Month, _inizio.Day, 0, 0, 0);
Button bt;
while (startTime.Date == _inizio.Date)
{
bt = new Button();
bt.Text = String.Format("{0:00}", startTime.Hour) + "." + String.Format("{0:00}", startTime.Minute);
bt.Size = new Size(50, 50);
bt.Location = new System.Drawing.Point(15 + startTime.Hour * 50, 15 + startTime.Minute * 5);
bt.Tag = startTime;
//abilitazione bottone
//Il bottone è abilitato se l'orario del bottone NON è presente nella tabella
//Se vuoi fare il contrario, togli il !
bt.Enabled = !_dtTodb.Contains(startTime);
btnTime.Add(startTime, bt);
this.groupBox1.Controls.Add(bt);
startTime = startTime.AddMinutes(15);
}
}
catch (Exception)
{
}
}