Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 :)

phillip Restall
Posted

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]

"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

Posted

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

phillip Restall

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...