hi there,
i have a datagrid view which has a calender column. in the datagridview row the calender column icon in the datagridview cell does not show, it appears as a datagridview text box,when you double click on the datagridview calender column cell,the datagridview calender column will display the calender column.

how can i make it display the calender column icon on a datagridviewcalender column cell as a row is added,
how can i do this

thanxxxxx

A little about how the cells are edited using the DataGridView.
When the user begins to edit a cell, a special edit control is automatically positioned over the cell, given the value of the cell and enabled.
There is only one edit control for each column, suitable for the column type. (In the case of the CalendarColumn this is a DateTimePicker).
There is only one edit control visible at once, that of the cell being edited.

It might be possible to get the effect you want by giving the Calendar Column focus after the row is added, making it the currently edited cell.
Not sure how you might do this though.
Try setting the CurrentCell property.

A little about how the cells are edited using the DataGridView.
When the user begins to edit a cell, a special edit control is automatically positioned over the cell, given the value of the cell and enabled.
There is only one edit control for each column, suitable for the column type. (In the case of the CalendarColumn this is a DateTimePicker).
There is only one edit control visible at once, that of the cell being edited.

It might be possible to get the effect you want by giving the Calendar Column focus after the row is added, making it the currently edited cell.
Not sure how you might do this though.
Try setting the CurrentCell property.

hey i didn't get the thing you were saying, i have uploaded a doc on the interface that I want looks like

thanxx

It should be possible by overriding the Paint event of the CalendarCell class.
This is not a small task and requires understanding of how to draw using the Graphics control.

It should be possible by overriding the Paint event of the CalendarCell class.
This is not a small task and requires understanding of how to draw using the Graphics control.

hey can you give a little help on this

thanxxx

Take a look at the RowPrePaint event. You can customise all or part of the way cells in a row are painted there. Just add code to paint the calednar image to the box in the relevant column.

Take a look at the RowPrePaint event. You can customise all or part of the way cells in a row are painted there. Just add code to paint the calednar image to the box in the relevant column.

hey how does this work, plase can you explain, i tried adding a datagridview and adding the code, dosen't work???

can you help me in this

thanxxx

did you attach the event handler to the datagridview or did you just copy the code straight into your project? The code given in the example is an event handler, if you dont connect the hnalder to an event it wont run.
See my tutorial to see how you set up event handlers correctly.

did you attach the event handler to the datagridview or did you just copy the code straight into your project? The code given in the example is an event handler, if you dont connect the hnalder to an event it wont run.
See my tutorial to see how you set up event handlers correctly.

hey yeah in the form load event i added this

private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.RowPrePaint += new DataGridViewRowPrePaintEventHandler(dataGridView1_RowPrePaint);
        }

thanxxxx

ok, so you have tied up your event handler correctly. Can you post the code in the handler and explain what (if anything) happens when the code runs

ok, so you have tied up your event handler correctly. Can you post the code in the handler and explain what (if anything) happens when the code runs

i don't know what is happening over in the below code

private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
             // Paints the custom selection background for selected rows.
       
// Do not automatically paint the focus rectangle.
            e.PaintParts &= ~DataGridViewPaintParts.Focus;

            // Determine whether the cell should be painted
            // with the custom selection background.
            if ((e.State & DataGridViewElementStates.Selected) ==
                        DataGridViewElementStates.Selected)
            {
                // Calculate the bounds of the row.
                Rectangle rowBounds = new Rectangle(
                    this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
                    this.dataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - this.dataGridView1.HorizontalScrollingOffset + 1,e.RowBounds.Height);

                // Paint the custom selection background.
                using (Brush backbrush = new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
                        this.dataGridView1.DefaultCellStyle.SelectionBackColor,
                        e.InheritedRowStyle.ForeColor,
                        System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
                {
                    e.Graphics.FillRectangle(backbrush, rowBounds);
                }
            
            }
        }

thanxxxxx

I posted the link to show you an example. The code you have pasted replaces the default highlighting for selected cells. Instead of the normal highlight colour it paints a horizontal gradient in the selected cell.

You need to examine the code, figure out what each part is doing and then adapt it to your needs. So find the part that determines the area to be painted, calculate where in that area you want to display the calender image, then use the e.Graphics object to paint the image to the cell.

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.