Question : DatetimePicker in datagridview MSDN example problem

Hello experts,

Need a little assistance with an MSDN example for Datetimepicker.

1- I added the class from MSDN  class CalendarColumn

2- added the following code after my datasource binds to the grid
 Dim col As New CalendarColumn()
       
        Dim row As DataGridViewRow
        For Each row In Me.grdStockItems.Rows
            row.Cells(8).Value = DateTime.Now
            row.Cells(9).Value = DateTime.Now
        Next row

But I only get a date in the column. I'm stepping through the class code. It compiles no errors...

Any ideas what I might be doing wrong?

Thank You
Cin

Answer : DatetimePicker in datagridview MSDN example problem


>> If I specifiy row.Cells(8).Value = DateTime.Now.Date  it only puts a date in the grid col not the control.

This means index 8 column is not a calendarcolumn. Presuming you have copied the classes from the msdn sample (as mentioned above by Ratuz),

to replace your existing column with a new calendar column, try the below code:

.
.
dataGridView1.Columns.RemoteAt(8);

CalendarColumn calenderColumn1 = new CalendarColumn();
dataGridView1.Columns.Insert(8, calenderColumn1);

dataGridView1.Columns.RemoteAt(9);

CalendarColumn calenderColumn2 = new CalendarColumn();
dataGridView1.Columns.Insert(9, calenderColumn2);


Then call your code
Dim row As DataGridViewRow
        For Each row In Me.grdStockItems.Rows
            row.Cells(8).Value = DateTime.Now
            row.Cells(9).Value = DateTime.Now
        Next row





Random Solutions  
 
programming4us programming4us