Groups | Blog | Home
all groups > vb.net > february 2005 >

vb.net : changing the color of the entire row in datagrid when a cell in the row has value greater than zero


hemant_pkl NO[at]SPAM yahoo.com
2/19/2005 9:41:23 PM
hello everybody,

I am having a datagrid which has data regarding customers. it has a
penalty column, and i want to show the entire record of the customer
in red whose penalty is greater than zero.

i have looked into the other messages which guide to override the
paint procedure of the datagrid, make a new class etc.

i am not able to understand the exact way of doing the mentioned
things.

i'll be thankful if somebody pours in some help.

Ken Tucker [MVP]
2/20/2005 7:03:43 AM
Hi,

Maybe selecting the row will work for you.

Dim conn As SqlConnection

Dim strConn As String

Dim strSQL As String

Dim da As SqlDataAdapter

Dim ds As New DataSet

strConn = "Server = (local);"

strConn &= "Database = NorthWind;"

strConn &= "Integrated Security = SSPI;"



conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * From Products", conn)

da.Fill(ds, "Products")

DataGrid1.DataSource = ds.Tables("Products")

For x As Integer = 0 To ds.Tables("Products").Rows.Count - 1

Dim dr As DataRow = ds.Tables("Products").Rows(x)

If CInt(dr.Item("UnitsInStock")) < 5 Then DataGrid1.Select(x)

Next



Ken

-----------------------

[quoted text, click to view]
hello everybody,

I am having a datagrid which has data regarding customers. it has a
penalty column, and i want to show the entire record of the customer
in red whose penalty is greater than zero.

i have looked into the other messages which guide to override the
paint procedure of the datagrid, make a new class etc.

i am not able to understand the exact way of doing the mentioned
things.

i'll be thankful if somebody pours in some help.

hemant.

Andy O'Neill
2/21/2005 1:21:04 PM
[quoted text, click to view]

I think if selecting the whole row is no good it'd be a hell of a lot easier
if you just highlit the textbox has the negative amount in it.
Check out george shepherd's faq site.
The datagrid section might have some ideas in it for you.

I suppose you could maybe mark an error in the row selector thing.

--
Regards,
Andy O'Neill

AddThis Social Bookmark Button