3

My Datagridview contains DateTimeColumn which overlaps the another next row column on scrolling. I had set the DatagridView properties like

AutoSizeColumnsMode : Fill

AutoSizeRowsMode: AllCellsExceptheaders

AllowUserstoAddRows: True

But it show me following result. Any Help will be great

enter image description here

My Code

  private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        try
        {
            if (e.RowIndex != -1)
            {
                if (e.ColumnIndex == 1 || e.ColumnIndex == 2)
                {

                    oDateTimePicker = new DateTimePicker();


                    dataGridView4.Controls.Add(oDateTimePicker);


                    oDateTimePicker.Format = DateTimePickerFormat.Short;


                    Rectangle oRectangle = dataGridView4.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);


                    oDateTimePicker.Size = new Size(oRectangle.Width, oRectangle.Height);


                    oDateTimePicker.Location = new Point(oRectangle.X, oRectangle.Y);
                    oDateTimePicker.TextChanged += new EventHandler(dateTimePicker_OnTextChange);
                    oDateTimePicker.Visible = true;
                }
            }
        }
        catch (Exception E)
        {
            MessageBox.Show(E.ToString());
        }
    }



    private void dateTimePicker_OnTextChange(object sender, EventArgs e)
    {

        dataGridView4.CurrentCell.Value = oDateTimePicker.Text.ToString();
    }
leppie
  • 115,091
  • 17
  • 196
  • 297
manraj
  • 151
  • 7

1 Answers1

1

It seems instead of a using real DataGridViewColumn you are aligning some DateTimePicker above the DataGridView.

Instead on aligning some DateTimePicker controls above your DataGridView you should create a custom DataGridViewColumn.

Here is a good MSDN Example that implements a CalendarColumn.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • how to make column 2 to CalendarColumn – manraj Nov 30 '15 at 06:35
  • The same way you make 2 column `TextBoxColumn`, It's the standard way of creating custom columns. You can use it in designer or by code. – Reza Aghaei Nov 30 '15 at 06:37
  • It's strongly recommended to use such approach but if for learning purpose or some reason else, you want to layout some controls above the grid, yo may find may answer [here](http://stackoverflow.com/a/32281605/3110834) helpful. – Reza Aghaei Nov 30 '15 at 06:40
  • Can you help me with this http://stackoverflow.com/questions/33751178/remove-dynamic-textboxes-on-checkedlistbox-selectedindexchanged – manraj Nov 30 '15 at 07:24
  • @manraj Unfortunately the question is closed and I can't post an answer, but the main idea is **-** When you click an item, add a text box to a flow layout panel, and set the textbox's tag property to index of checked item. Then when unchecking an item, you can simply find the textbox based on its tag and remove it. – Reza Aghaei Nov 30 '15 at 07:37
  • @manraj check the link again. It seems it's an answered question. – Reza Aghaei Dec 08 '15 at 11:05
  • Please help me with this http://stackoverflow.com/questions/34348440/how-to-bring-database-online-in-my-online-site – manraj Dec 18 '15 at 04:25