phillip Posted June 23, 2004 Posted June 23, 2004 I Have a datagrid that has a datatable. I have filled the table with data but want to Change the colour of one Row. How do i do this? Ps. I'm a bit of a newb :) Quote phillip Restall
Arch4ngel Posted June 23, 2004 Posted June 23, 2004 I'm currently using this (only way I found...): [size=2][color=#0000ff]private[/color][/size][size=2] [/size][size=2][color=#0000ff]void[/color][/size][size=2] dgPosts_ItemCreated([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { [/size][size=2][color=#0000ff]if[/color][/size][size=2]( e.Item.ItemIndex == 1 ) { e.Item.BackColor = Color.LightGray; } } I'm using this code also... so I search a lot to find the better way to do it... but this one is really the best (at least... I think) [/size] Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
phillip Posted June 23, 2004 Author Posted June 23, 2004 I should have mentioned that its not a web form Quote phillip Restall
phillip Posted June 24, 2004 Author Posted June 24, 2004 I managed to find this code that works, The problem is it works when the form loads How would i merge this into a current routine rather that the form loading? :confused: Add custom code for the datagrid Paint event. Private Sub Grid_Paint(ByVal sender As Object, ByVal e As system.Windows.Forms.PaintEventArgs) Handles Grid.Paint Dim Myrect As Rectangle Dim row as Integer = 0 Dim column as Integer = 0 Myrect = Grid.GetCellBounds(row, column) e.Graphics.DrawRectangle(new Pen(color.red), myrect) e.Graphics.FillRectangle(New SolidBrush(Color.Red), Myrect) e.Graphics.DrawString(Grid.Item(row, column), Grid.Font, New SolidBrush(Color.White), Myrect.X, Myrect.Y) End Sub Quote phillip Restall
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.