Conditional Formatting Of Windows Form DataGrid Rows

Hi.,
I want to change the color of datagrid row at runtime. I have a Windows form (vb.net). On that form i have 3 datagrid some binded to dataset and some to arraylist. I have applied the table style's also. I want to change the one of my datagrid  row color on some data condition, and this formating should apply for a particular datagrid and other should not be distrub. I receive the new data in dataset and arraylist every one miniute. I am showing new data in datagrid (append rows). So how can i change the color of the datagrid and when the new row is added to datagrid i sort them in desc so i can get the new values first but when the client area of datagrid is filled means when scroll bar of datagrid get visible then the selected index is not set to the first row.. Its still on the old row how can i slove these problem.

Regarding conditional formatting i have seen meany example but i was not able to apply them for a single datagrid, when i applied it all the datagrid color changes ie all 3 datagrid.

Thanks in advance
Regards
skulldenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arif_eqbalCommented:
I hope you are using DataGridTableStyle to format your DataGrid now and you must be using DatagridTextBoxColumn object to format it.

What you do is use DataGridFormattableTextBoxColumn and Handle its event so that at runtime you can decide the row/cell color based on your text

Use

Dim FormatCell as DataGridFormattableTextBoxColumn
FormatCell = New DataGridFormattableTextBoxColumn(0) 'Column No

'Rest of the things As You do
FormatCell.MappingName = DataTable1.Columns(0).ColumnName
FormatCell.HeaderText = DataTable1.Columns(0).ColumnName

'Then
AddHandler FormatCell.SetCellFormat, AddressOf CellFormatHandler


Now the CellFormatHandler Event

    Private Sub CellFormatHandler (ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
         'I THINK THIS IS WHAT YOU NEED, CHECK IF THE ROW BEING PAINTED HAS THE REQUIRED TEXT AT COLUMN 0, IF YES COLOR THE ROW AS RED
         'Here e.Row contains the Row Number which is being Painted so
         If CType(dataGrid1.DataSource, DataTable).Rows(e.Row).Item(0) = "MyValue" Then
            e.BackBrush = Brushes.Red
        End If
End Sub


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skulldenAuthor Commented:
Hi.,
Thanks for the quick response.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.