private void btnImport_Click(object sender, EventArgs e) { using (StreamReader sr = new StreamReader(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Schedule.txt")) { GrvSchedule.DataSource = null; GrvSchedule.Rows.Clear(); GrvSchedule.Columns.Clear(); GrvSchedule.Refresh(); DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Start Date"); dt.Columns.Add("TIME"); string newline; while ((newline = sr.ReadLine()) != null) { DataRow dr = dt.NewRow(); var y = string.Join(".", newline.Split(',').Skip(1)); string[] values = y.Split('.'); for (int i = 0; i < values.Length; i++) { dr[i] = values[i]; } dt.Rows.Add(dr); } sr.Close(); GrvSchedule.DataSource = dt; } }
//Input Schedule private void GrvSchedule_CellClick(object sender, DataGridViewCellEventArgs e) { // If any cell is clicked on the Second column which is our date Column if (e.ColumnIndex == 1) { //Initialized a new DateTimePicker Control oDateTimePicker = new DateTimePicker(); //Adding DateTimePicker control into DataGridView GrvSchedule.Controls.Add(oDateTimePicker); // Setting the format (i.e. 2014-10-10) oDateTimePicker.Format = DateTimePickerFormat.Short; // It returns the retangular area that represents the Display area for a cell Rectangle oRectangle = GrvSchedule.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); //Setting area for DateTimePicker Control oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height); // Setting Location oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y); // An event attached to dateTimePicker Control which is fired when DateTimeControl is closed oDateTimePicker.CloseUp += new EventHandler(oDateTimePicker_CloseUp); // An event attached to dateTimePicker Control which is fired when any date is selected oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange); // Now make it visible oDateTimePicker.Visible = true; } if (e.ColumnIndex == 2) { //Initialized a new DateTimePicker Control oDateTimePicker = new DateTimePicker(); //Adding DateTimePicker control into DataGridView GrvSchedule.Controls.Add(oDateTimePicker); // Setting the format (i.e. 2014-10-10) oDateTimePicker.Format = DateTimePickerFormat.Custom; oDateTimePicker.CustomFormat = "HH:mm:ss"; oDateTimePicker.ShowUpDown = true; // It returns the retangular area that represents the Display area for a cell Rectangle oRectangle = GrvSchedule.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); //Setting area for DateTimePicker Control oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height); // Setting Location oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y); // An event attached to dateTimePicker Control which is fired when DateTimeControl is closed oDateTimePicker.CloseUp += new EventHandler(oDateTimePicker_CloseUp); // An event attached to dateTimePicker Control which is fired when any date is selected oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange); // Now make it visible oDateTimePicker.Visible = true; } }