Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6205171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:13:29+00:00 2026-05-24T05:13:29+00:00

i have datagrid(see bellow) there is columns with date time how i can make

  • 0

i have datagrid(see bellow) there is columns with date time how i can make background red where rooomNumer is 777 from 1/8/2011 to 5/8/2011 with code behind? Room number column bind with observable collection

 ObservableCollection<RoomsInfoData> _RoomsInfoCollection = new ObservableCollection<RoomsInfoData>();
        public RoomsInfo()
   public ObservableCollection<RoomsInfoData> RoomsInfoCollection
        {
            get { return _RoomsInfoCollection; }
        }

        public class RoomsInfoData
        {
            public string RoomType { get; set; }
            public string RoomNumber { get; set; }
            public string RoomStatus { get; set; }
        }
HProDataContext db = new HProDataContext();
            var _RoomNumber = (from d in db.SelectRooms select d.roomnumber).ToList();
            var _RoomType = (from d in db.SelectRooms select d.roomtype).ToList();
            var _RoomStatus = (from d in db.SelectRooms select d.status).ToList();

            for (int i = 0; i < _RoomNumber.Count; i++)
            {

                _RoomsInfoCollection.Add(new RoomsInfoData { RoomNumber = _RoomNumber[i], RoomType = _RoomType[i], RoomStatus = _RoomStatus[i] });
            }

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:13:30+00:00Added an answer on May 24, 2026 at 5:13 am

    Assuming that

    1. “this” refers to your window or user control in which this data grid is placed.
    2. this.dataGrid refers to your datagrid in which you have added columns from code behind.

    We will specify a style in the Window / UserControl’s Resources collection … like this

        <UserControl.Resources> <!-- could be Window.Resources if datagrid lies in a Window -->
                <Style x:Key="RoomNumberValidationCellStyle"
                           TargetType="{x:Type DataGridCell}"> <!-- DataGridCell because we need to apply this style to specific columns -->
                        <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=RoomNumber}" Value="777">
                                        <Setter Property="Background" Value="Red" />
                                </DataTrigger>
                        </Style.Triggers>
                </Style>
        </UserControl.Resources>
    

    in code behind after you set all columns to this.dataGrid … do this…

        foreach(var col in this.dataGrid.Columns)
        {
                var headerText = (string)col.Header;
                if (headerText == "1/8/2011" || headerText.Header == "2/8/2011"
                || headerText.Header == "3/8/2011" || headerText.Header == "4/8/2011"
                || headerText.Header == "5/8/2011")
                        col.CellStyle = this.FindResource("RoomNumberValidationCellStyle") as Style;
        }
    

    Let me know if this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you can see, I have two DataGrid s in my app. For reasons
I have a DataGrid in WPF with Auto Generated Columns. Sometimes there are DateTime
I have a DataGrid with 5 template columns, However when I try and add
Hi I have a datagrid that has a number of datagridtemplate columns that are
The situation is simple. I have a datagrid that gets its data from a
I have a flex datagrid that I would like to remove contents from after
I have a datagrid where a row can be deleted (using ajax). I'm have
I have a WPF DataGrid templatecolumn that has a DataTemplate for an AutoCompleteBox from
I have a WPF DataGrid with some data. You can add rows through a
I'm having trouble pasting from a csv into the wpf datagrid - I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.