Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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());
}
}
Posted
Comments
HBBFXY 2-Aug-13 4:20am    
Thank you very much for your help, in fact, does not need to bind datagridview data source. In accordance with the number of days per month dynamically generate a calendar, the calendar has checkbox controls. Once again, thank you for your answer!

1 solution

C#
string qry2 = "Select * from student";
           SqlCommand cmd2 = new SqlCommand(qry2, sconn);
           SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
           DataTable dt2 = new DataTable();
           da2.Fill(dt2);
           BindingSource bs2 = new BindingSource();
           bs2.DataSource = dt2;
           dataGridView2.DataSource = bs2;
           DataGridViewCheckBoxColumn colCB = new DataGridViewCheckBoxColumn();
           colCB.HeaderText = "Delete";
           colCB.ValueType = typeof(System.Boolean);
           colCB.TrueValue = "True";
           colCB.FalseValue = "False";
           dataGridView2.AutoGenerateColumns = false;
           dataGridView2.Columns.Insert(0, colCB);

           dataGridView2.Columns[0].Width = 40;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900