0

I have a datagrid connected to a msql-server database. User can enter there worktime information there. The columns are e.g. Starttime, Endttime, Date, Projectname etc.
Usually I use a combobox with a link to a specific table to fill the datagrid. E.g. There is a Table Project in my sql database with the field Project_ID, Project_Name. The Project_ID field is also in the Table Time Collector so I set the datasource, member and valuemember and get what I want.

For the start and end time columns I wanna have a dropdown with time in 15 minute intervals and for the Date column I wanna have a defaulted date of "Now" and a datetimepicker. But I have absolutley no idea how to implement that. I could set up a table with all the times give it an id and bind it but that looks to me like cracking a nut with a sledgehammer.

It would be great if one of you could help me with it.

I am using visual studio 12 express.

matzone
  • 5,703
  • 3
  • 17
  • 20
ruedi
  • 5,365
  • 15
  • 52
  • 88

1 Answers1

0

Use a datepicker for the date, create a dropdownlist and populate with the following for the time part.

dim mTimeIntervals as list(of string)


        Dim start As New DateTime(1900, 1, 1, 0, 0, 0)
        Dim [end] As New DateTime(1900, 1, 1, 23, 45, 0)
        Dim current As DateTime = start
        While current <= [end]
            l.add(current.ToString("HH:mm"))
            current = current.AddMinutes(15)
        End While

dropdownlist1.datasource = mTimeIntervals
GJKH
  • 1,715
  • 13
  • 30
  • datagrid implementation .. ? – matzone May 15 '13 at 19:15
  • Ah - sorry missed that, you can host controls in cells, the code above still applies, use a combobox as one of your fields and bind it with the code above. In order to host a datepicker control in a cell you can take a look here: http://stackoverflow.com/questions/8561300/how-to-add-datepicker-column-in-gridview-design-winforms and here http://www.codeproject.com/Articles/9558/How-to-add-selection-controls-to-your-DataGrid – GJKH May 16 '13 at 13:04
  • the last link is probably more useful in your case as a working example. – GJKH May 16 '13 at 13:05