I want a personalized calendar, using datagridview, at the same time I want to add checkbox controls (not the template in datagridview column). But my problem is that when I insert checkbox when successful, checbox.Text values are not displayed. Give me an idea of it?
this is my snick code:
private void Form1_Load(object sender, EventArgs e)
{
DrawCalendor(2013, 9);
}
private void DrawCalendor(int year, int month)
{
DateTime time = new DateTime(year, month, 14);
string[] WeekInfo = new string[] { "Sunday", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday " };
foreach (string element in WeekInfo)
{
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.SortMode = DataGridViewColumnSortMode.NotSortable;
column.HeaderText = element;
dataGridView1.Columns.Add(column);
}
dataGridView1.Rows.Add(6);
int num = 0;//jishu
int week = Convert.ToInt16(DateTime.Parse(time.ToString("yyyy年MM月01日")).DayOfWeek);
int monthdays = DateTime.DaysInMonth(year, month);
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (i > 0)
{
week = 0;
}
for (int j = week; j < dataGridView1.Columns.Count; j++)
{
num++;
if (num > monthdays)
{
break;
}
CheckBox chk = new CheckBox();
chk.Name = num.ToString();
chk.Size = new Size(15, 15);
chk.Text = num.ToString ();
chk.TextAlign = ContentAlignment.MiddleCenter;
this.dataGridView1.Controls.Add(chk);
Rectangle reg = dataGridView1.GetCellDisplayRectangle(j, i, true);
chk.Left = reg.Left+4;
chk.Top = reg.Top+5;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}