Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. change datagridrow color after add it

change datagridrow color after add it

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Defender NF
    wrote on last edited by
    #1

    hello i would like to change the background of the added row in a datagrid. is there any way to get the added row and change its background? Thanks

    N P N R 4 Replies Last reply
    0
    • D Defender NF

      hello i would like to change the background of the added row in a datagrid. is there any way to get the added row and change its background? Thanks

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      First please tell us the environment. The answer will be different between Windows and Web


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • D Defender NF

        hello i would like to change the background of the added row in a datagrid. is there any way to get the added row and change its background? Thanks

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Defender-NF wrote:

        is there any way to get the added row and change its background?

        Yes. Without some context of what you environment you are trying to run this from, we can't really offer anymore help.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        D 1 Reply Last reply
        0
        • P Pete OHanlon

          Defender-NF wrote:

          is there any way to get the added row and change its background?

          Yes. Without some context of what you environment you are trying to run this from, we can't really offer anymore help.

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          D Offline
          D Offline
          Defender NF
          wrote on last edited by
          #4

          Ah sorry. I m working on visual studio 2010 ultimate, wpf/c# my datagrid are bound to some generic lists/datasets via simple itemsource-bindings. Thanks

          P 1 Reply Last reply
          0
          • D Defender NF

            Ah sorry. I m working on visual studio 2010 ultimate, wpf/c# my datagrid are bound to some generic lists/datasets via simple itemsource-bindings. Thanks

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            There are a few ways you could achieve this. Without knowing how you are going to determine what triggers a new colour, I can't be any more specific other than to say that you could look at using a different item template using an ItemTemplateSelector, or you could use a DataTrigger to set the background colour. Either mechanism would suffice.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            D 1 Reply Last reply
            0
            • P Pete OHanlon

              There are a few ways you could achieve this. Without knowing how you are going to determine what triggers a new colour, I can't be any more specific other than to say that you could look at using a different item template using an ItemTemplateSelector, or you could use a DataTrigger to set the background colour. Either mechanism would suffice.

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              D Offline
              D Offline
              Defender NF
              wrote on last edited by
              #6

              Okay, so wich property can i use for the Trigger or the Datatrigger? I mean is there something like "IsAdd" as a property? The only thing i found is "IsEditing" but i wanna the row change its background only if its a "new" row.

              P 1 Reply Last reply
              0
              • D Defender NF

                Okay, so wich property can i use for the Trigger or the Datatrigger? I mean is there something like "IsAdd" as a property? The only thing i found is "IsEditing" but i wanna the row change its background only if its a "new" row.

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Defender-NF wrote:

                I mean is there something like "IsAdd" as a property?

                No. If you think about it, the data grid will treat all rows initially as a new row because it has no interaction with the database. You will have to provide some context for it to be able to figure out what a new row is; for instance, you might have an IsSaved property on your data. The key is to look at the data, rather than at the datagrid for the mechanism to add this.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                D 1 Reply Last reply
                0
                • P Pete OHanlon

                  Defender-NF wrote:

                  I mean is there something like "IsAdd" as a property?

                  No. If you think about it, the data grid will treat all rows initially as a new row because it has no interaction with the database. You will have to provide some context for it to be able to figure out what a new row is; for instance, you might have an IsSaved property on your data. The key is to look at the data, rather than at the datagrid for the mechanism to add this.

                  Forgive your enemies - it messes with their heads

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  D Offline
                  D Offline
                  Defender NF
                  wrote on last edited by
                  #8

                  Thanks Pete for the Assistance I already have some solutions for this based on my database.. but i dont wanna programm on all my classes/datasets/lists new property just to do this? thats why i m looking on a interface-way to resolve that, or maybe an independency function or something, i tryed for example this:

                   void la2\_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
                      {
                          if (e.Action == NotifyCollectionChangedAction.Add)
                          {
                  
                              emp.NewRowAfterFiltering = true;
                             
                          }
                      }
                  

                  NewRowAfterFiltering is a property wich i bound to the the datatriger of the gridrow to change background, but it didnt work.

                  D 1 Reply Last reply
                  0
                  • D Defender NF

                    Thanks Pete for the Assistance I already have some solutions for this based on my database.. but i dont wanna programm on all my classes/datasets/lists new property just to do this? thats why i m looking on a interface-way to resolve that, or maybe an independency function or something, i tryed for example this:

                     void la2\_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
                        {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                    
                                emp.NewRowAfterFiltering = true;
                               
                            }
                        }
                    

                    NewRowAfterFiltering is a property wich i bound to the the datatriger of the gridrow to change background, but it didnt work.

                    D Offline
                    D Offline
                    Defender NF
                    wrote on last edited by
                    #9

                    ok i got it, but the rowbackground goes to the old value after the header got clicked, any idea how can i get in the way of that? thanks

                    1 Reply Last reply
                    0
                    • D Defender NF

                      hello i would like to change the background of the added row in a datagrid. is there any way to get the added row and change its background? Thanks

                      N Offline
                      N Offline
                      Nilesh G Umaretiya
                      wrote on last edited by
                      #10

                      ********************************************************************************************* ---------------> .aspx code <------------------------------------------------ ***************************************************************************************** *********************** CSS Code ******************** .tabe_1 { margin:0px; overflow:auto; padding:0px 0px 0px 0px; color:#0F7371; font-weight:bold; line-height:31px; font-size:13px; font-family:Verdana, Arial,sans-serif; background:url(../images/tabe_1_bg.jpg) repeat-x top #F8F8F8; } .tabe_2 { margin:0px; padding:0px; overflow:auto; font-size:17px; height:53px; background:url(../images/rows_bg.png) repeat-x top #F3FDFE; line-height:normal; color:#000000; vertical-align:middle; } .tabe_3 { margin:0px; overflow:auto; padding:0px; font-size:18px; height:33px; background:url(../images/rows_bg1.png) repeat-x top #F8F8F8; line-height:normal; vertical-align:middle; } ********************************************************

                      P 1 Reply Last reply
                      0
                      • N Nilesh G Umaretiya

                        ********************************************************************************************* ---------------> .aspx code <------------------------------------------------ ***************************************************************************************** *********************** CSS Code ******************** .tabe_1 { margin:0px; overflow:auto; padding:0px 0px 0px 0px; color:#0F7371; font-weight:bold; line-height:31px; font-size:13px; font-family:Verdana, Arial,sans-serif; background:url(../images/tabe_1_bg.jpg) repeat-x top #F8F8F8; } .tabe_2 { margin:0px; padding:0px; overflow:auto; font-size:17px; height:53px; background:url(../images/rows_bg.png) repeat-x top #F3FDFE; line-height:normal; color:#000000; vertical-align:middle; } .tabe_3 { margin:0px; overflow:auto; padding:0px; font-size:18px; height:33px; background:url(../images/rows_bg1.png) repeat-x top #F8F8F8; line-height:normal; vertical-align:middle; } ********************************************************

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #11

                        It's a WPF application.

                        Forgive your enemies - it messes with their heads

                        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                        1 Reply Last reply
                        0
                        • D Defender NF

                          hello i would like to change the background of the added row in a datagrid. is there any way to get the added row and change its background? Thanks

                          R Offline
                          R Offline
                          robertalis
                          wrote on last edited by
                          #12

                          Hi, You can get solution to your problem here to change the background of the added row in a data grid. Using this you can set specific appearance of the element via Appearance property. For instance, Grid.Appearance, Header.Appearance, Column.Appearance, Row.Appearance, Cell.Appearance. Visit here and have a look http://www.dapfor.com/Feature.aspx?id=custom_painting[^]

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups