Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
        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
            'MessageBox.Show(ex.Message)
        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
Posted
Updated 13-Feb-14 22:21pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900