I'm trying to create a win forms application where a user can fill in events that will happen each day of the year. The textboxes will be generated by a script. The textbox needs to be given the ID of the day and month so it can be found when it is saved. But the problem is the form application is blank when run. Help a begginer out please.

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        DateTime Current_Year = new DateTime(DateTime.Now.Year, 1, 1);
        public TextBox[] TxBxArray = new TextBox[366];

        public Form1()
        {
            InitializeComponent();
            int year_length = 365;
            if (DateTime.IsLeapYear(DateTime.Now.Year)) year_length = 366;
            for (int i = 0; i < year_length; i++)
                {
                    TxBxArray[i] = new TextBox();
                    TxBxArray[i].Name = Current_Year.ToString("dd/MM");
                    TxBxArray[i].Location = new System.Drawing.Point(20, 30 + 40 * i);
                    TxBxArray[i].Size = new System.Drawing.Size(184, 20);
                    Current_Year.AddDays(1);
                }
            
        }
    }
}

Recommended Answers

All 7 Replies

You have to add your textboxes to the control collection of the form.
this.Controls.Add(MyTextBox);
this refers to the form.
There is also an AddRange method.

Exactly. In your particular case you do:

this.Controls.Add(TxBxArray[i]);

Exactly. In your particular case you do:

this.Controls.Add(TxBxArray[i]);

The only problem in my script is that all the dates are the 01/01. Why isnt the date increasing?

You didnt set any varible to change it. You have to do it:

Curent_Year = Current_Year.AddDays(1); //on the end of the code!

I have a service based database called Events and a datasource called EventsDataSet and a table called Events within the database and a date and event collumn in the table. When I want to save I want a new row to be added to the table. Im strugling to add the new row in code. Could I have help?

EventsDataSet.EventsRow newEventsRow = 
EventsDataSet.EventsRow.NewEventsRow(); //does not contain a definition for 'NewEventsRow'

newEventsRow.date = TxBxArray[i].Name;
newEventsRow._event = TxBxArray[i].Text;

EventsDataSet.Events.Rows.Add(NewEventsRow); // The name 'NewEventsRow' does not exist in the current context

What are my needed corrections

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.