rahul agarwal

rahul agarwal

  • NA
  • 118
  • 654

how to add calendar in datagridview column

Sep 14 2017 4:15 AM
hi,
 
I am doveloping software for desktop solution on visual studio 2010 using c# language. But i have a problem to add a calendar in datagridView column.
 
i am waiting for u anwser.
 
pls rply me ASAP.
 
thanks.. 
 
 
using this code
 
 
private void dataGridView1_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
dataGridView1.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 = dataGridView1.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;
}
}
private void dateTimePicker_OnTextChange(object sender, EventArgs e)
{
// Saving the 'Selected Date on Calendar' into DataGridView current cell
dataGridView1.CurrentCell.Value = oDateTimePicker.Text.ToString();
}
void oDateTimePicker_CloseUp(object sender, EventArgs e)
{
// Hiding the control after use
oDateTimePicker.Visible = false;
}
 
 
its not working.. 
 

Answers (1)