Hi All,
I don't know if it's possible, but I would like to check if the cell value corresponds to Header value, if yes - color cell. I have created a calendar in datagrid which, after selecting the dates from DateTimePickers creates a column with the date corresponding to the selected date and imports data from a SQL table.
http://oi59.tinypic.com/kcjvix.jpg[
^]
This is my app. The code:
Dim sql As String
DataGridView1.DataContext = Nothing
DataGridView1.Columns.Clear()
DataGridView1.Visibility = Windows.Visibility.Visible
Dim sDate As DateTime = Format(DateTimePicker1.SelectedDate, "MM/dd/yyyy")
Dim eDate As DateTime = Format(DateTimePicker2.SelectedDate, "MM/dd/yyyy")
sql = "SELECT Enumber, StartDate, EndDate from tbl_Test where StartDate = '" & sDate & "' AND EndDate = '" & eDate & "' "
Dim da As New SqlDataAdapter(sql, cnn)
Try
Dim dt As New DataTable("Accs")
da.Fill(dt)
DataGridView1.ItemsSource = dt.DefaultView
Dim startDate As DateTime = DateTimePicker1.SelectedDate
Dim endDate As DateTime = DateTimePicker2.SelectedDate
Dim numberOfDays As Integer = ((endDate.Date) - (startDate.Date)).Days + 1
For dayCount As Integer = -1 To (numberOfDays - 0)
Dim currentDate As Date = Convert.ToDateTime(startDate.AddDays(dayCount))
Dim formatedD As String = currentDate.ToString("dd")
If currentDate.DayOfWeek <> DayOfWeek.Saturday AndAlso currentDate.DayOfWeek <> DayOfWeek.Sunday Then
Dim c1 As New DataGridTextColumn
c1.Header = formatedD
DataGridView1.Columns.Add(c1)
End If
Next dayCount
dt = Nothing
da.Dispose()
cnn = Nothing
Catch ex As Exception
End Try
Scenario:
An employee selects the dates from DateTimePickers
On button click DataGrid will appear with automatically generated columns.(of the days)
If the columns StartDate and EndDate (columns taken from the table) are the dates - the cells corresponding to those dates change to blue.
Thank you very much for your help!
BR