Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I have made a calendar, every date, 1,2 ..31 is a button.
The calendar returns the current month by default.
And I am putting everything in TableGridLayout

But I have a problem when i want to print dates inside the cells, as i got confused..!


C#
 Button[] buttons = new Button[numberOfDaysInMonth];
            int day = firstDayAsNumber;//this is the first day of moneth, if it is 0 
//then the first day will go to column 0
            int row = 0;//this row must be 0 again after it fills the first row
            for (int i = 0; i < buttons.Length; i++)
            {
                
                buttons[i] = new Button();
                buttons[i].Name = "Button" + i.ToString();
                buttons[i].Text = i.ToString();
                table1.Controls.Add(buttons[i], day, 0); /*PROBLEM HERE!!??!*/
                         }
        }


Please help me
Posted
Comments
wizardzz 27-Mar-12 16:38pm    
Please explain your "problem".
Sergey Alexandrovich Kryukov 27-Mar-12 16:39pm    
Not clear. What's the idea? Why buttons? As you do not handle click event of a button, it should not be used. How it can be related to "print"?
--SA
csharpnew 27-Mar-12 16:58pm    
I will handle it later,
the problem is that i want to fit all buttons in the table layout.

My guess is that you are trying to add multiple controls to the same cell in your layout as you are not incrementing or using the row variable (or the day variable for that matter).
 
Share this answer
 
v2
Comments
csharpnew 27-Mar-12 17:07pm    
Yes, i know but how to do it ??
I am working since long but it couldnt work with me,
[no name] 27-Mar-12 17:22pm    
You will need nested loops for your rows and columns on you TableLayoutPanel
csharpnew 27-Mar-12 17:27pm    
for (int i = 0; i < buttons.Length; i++)
{

buttons[i] = new Button();
buttons[i].Name = "Button" + i.ToString();
buttons[i].Text = i.ToString();
table1.Controls.Add(buttons[i], day, row);
++day;
// MessageBox.Show("day now is after++" + day);
//MessageBox.Show("row now is " + row);
if (day == 6) {
day = 0;
}
if ((day) % 6 == 0) {
row++;
}

}
C#
for (int i = 0; i < buttons.Length; i++)
          {

              buttons[i] = new Button();
              buttons[i].Name = "Button" + i.ToString();
              buttons[i].Text = i.ToString();
              table1.Controls.Add(buttons[i], day, row);
              ++day;
            //  MessageBox.Show("day now is after++" + day);
              //MessageBox.Show("row now is " + row);
              if (day == 6) {
                  day = 0;
              }
              if ((day) % 6 == 0) {
                  row++;
              }

          }



the last cell is empty it prints like this
like everything under Sat is emptyutput
i wish i could show u the p
Sun Mon Tue Wed Thur Fri Sat
1 ....2
3...4....5...6....7....8
9..

why is that ???
 
Share this answer
 
v2

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