Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • How do I change the background color of an AgDataGridRow in code (not in XAML)?

                                0

                                Hi Robert,

                                I'm afraid there is no easy way to change the row color in code behind.

                                However, from your post I do not quite understand the necessity to do this. Can you please describe the task you're trying to accomplish in this manner in as much detail as possible? Perhaps, there is an alternative way to implement this functionality?

                                Thanks,
                                Vito

                                0

                                I have an application that requests updated data from the server on a timer and when a row of data is updated, I want to change the background color of that row to indicate a change for a short period of time. Sort of like a stock program monitoring stocks indicating when values change. Here is the code I am using to get the AgDataGridRowBase:
                                      If m_gridDataSource IsNot Nothing Then
                                         For Each tempBrandAuction In m_gridDataSource
                                            pos = m_gridDataSource.IndexOf(tempBrandAuction)
                                            tempRow = AgDataGrid1.GetRow(AgDataGrid1.GetRowHandleByListIndex(pos))
                                            'have row, change color here
                                         Next
                                      End If

                                0

                                Hi Robert,

                                Thank you for the response.

                                It is required to slightly modify the grid's DataRowTemplate. After that, you'll be able to accomplish this task by modifying the AgDataGridRow's Background property value.

                                Attached is a small sample, illustrating this approach in action. Hopefully, it will be of some help.

                                Thanks,
                                Vito

                                DXSample.zip
                                0

                                Ok, that works great. Now, since I can't see the original RowTemplate, I don't know what you changed to make it work.
                                1. Can you detail the changes that apply to making this work so I can understand it better?
                                2. Suggestion: Make the change in the default RowTemplate so we don't have to go though this in the future. I would think we should be able to directly affect any std Style property (colors, fonts, displayFormats, enable/disable, etc)

                                0

                                Hi Robert,

                                I apologize for providing insufficient information.

                                I only added binding to the row's Background property. Here is the modified part of the template:

                                [XAML]
                                <ControlTemplate TargetType="dxg:AgDataGridRow"> <Grid Name="RootElement" Background="{TemplateBinding Background}">

                                As for the problem as a whole, we've already been asked for a similar functionality, and will consider adding an event, which will allow changing a style of a row conditionally. Please track the following suggestion:

                                ID: S31936, Add an event similar to RowCellStyle in XtraGrid

                                Thanks,
                                Vito

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners