How to get the time, using a textbox

1

I am developing something similar to an activities agenda, in which the user can choose the days in which he wishes the agenda to apply as well as the activities of the same, the problem that I have is that in the agenda the user you must choose the time at which your agenda starts, for example, the user enters a textbox where his activities begin at 8:23 a.m. then the program must take that data and save it and then deploy it in a datagridview control with the name of the respective activity.

Example

 -actividad - hora-
 ---------------------------
-junta     - 08:23 - 9:30 -
-desayuno  - 09:30 - 10:20-
-etc                      -     
-etc                      -
---------------------------

the duration of the activities are already predefined so there is no problem with that. The problem as I said, is that I do not know how to save the information that the user enters in the textbox and that the program knows that it refers to a time and not a string for example.

 private void button5_Click(object sender, EventArgs e)
    {
        checkedListBox1.Visible = false;
        comboBox1.Enabled = false;
        comboBox2.Enabled = false;
        textBox2.Enabled = false;
        button3.Enabled = false;
        button2.Enabled = false;
        DateTime hi = DateTime.ToString("HH:MM");


        if (checkBox1.Checked == true)
        {
            //this.dataGridView2.Rows[1].Cells[1].Value = this.comboBox1.SelectedText;
            dataGridView2.Rows.Add(comboBox1.Text);
            dataGridView2.Rows.Add(hi);
        }
        if (checkBox2.Checked == true)
        {
            //this.dataGridView2.Rows[1].Cells[1].Value = this.comboBox1.SelectedText;
            dataGridView3.Rows.Add(comboBox1.Text);
        }
        if (checkBox3.Checked == true)
        {
            //this.dataGridView2.Rows[1].Cells[1].Value = this.comboBox1.SelectedText;
            dataGridView4.Rows.Add(comboBox1.Text);
        }
        if (checkBox4.Checked == true)
        {
            //this.dataGridView2.Rows[1].Cells[1].Value = this.comboBox1.SelectedText;
            dataGridView5.Rows.Add(comboBox1.Text);
        }
        if (checkBox5.Checked == true)
        {
            //this.dataGridView2.Rows[1].Cells[1].Value = this.comboBox1.SelectedText;
            dataGridView6.Rows.Add(comboBox1.Text);
        }

        //MessageBox.Show("Los datos han sido guardados, cambios no permitidos \nPara hacer cambios necesita limpiar los datos \nPulse ''Limpiar Datos'' para hacerlo");
    }

I hope and someone can help me. Greetings

    
asked by user7070220 25.10.2016 в 19:15
source

1 answer

2

Why do not you use the datetimepicker ? If you want to use it with a textBox anyway, what you have to do is convert your string from your textBox to dateTime (this in case you want to use it for a future reference, you can do without this conversion) and same way to your column you must add a format.

        tuDGV.Rows.Add(DateTime.ParseExact(tuTextBoxVaAqui.Text,"HH:mm",System.Globalization.CultureInfo.InvariantCulture));
        tuDGV.Columns[0/*el número de tu columna acá*/].DefaultCellStyle.Format = "HH:mm";//<-formato de Horas/minutos

Greetings

    
answered by 25.10.2016 / 23:55
source