Hello all,
I am having problems finding an answer to row conditional formatting in VB.Net 2005 using the datagridview control on a windows form.
I am pulling data from a stored procedure and dumping it into a datagridview (NOT A .NET 2003 DATAGRID). Once the data is loaded how do I change the row backcolor if the value of a cell (a check box) is marked as being checked?
Basically if the cell's check box is checked on any given row (and there are many rows) the row backcolor needs to be changed to red, otherwise the row backcolor should be displayed as white.
Here is the code that loads the stored procedure to my datagrid:
Thanks for any help,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
I am having problems finding an answer to row conditional formatting in VB.Net 2005 using the datagridview control on a windows form.
I am pulling data from a stored procedure and dumping it into a datagridview (NOT A .NET 2003 DATAGRID). Once the data is loaded how do I change the row backcolor if the value of a cell (a check box) is marked as being checked?
Basically if the cell's check box is checked on any given row (and there are many rows) the row backcolor needs to be changed to red, otherwise the row backcolor should be displayed as white.
Here is the code that loads the stored procedure to my datagrid:
Code:
Private Function GetValues() As Boolean
Dim returnVals As New SqlCommand 'Variable to hold sql command
Dim oSQLConn As SqlConnection = New SqlConnection() 'Variable to hold connection to the server
Dim recreturned As Integer 'Variable to hold the number of records returned from sql server
GetValues = False
'Clear any existing data from datagrid
Call ClearDataGrid()
Windows.Forms.Cursor.Current = Cursors.WaitCursor
oSQLConn.ConnectionString = "Data Source=" & ServerName & ";Integrated Security=SSPI;Initial Catalog=InHouseGLS"
With returnVals
.Connection = oSQLConn
.CommandText = "sp_frmInvoices"
.CommandType = CommandType.StoredProcedure
End With
Try
oSQLConn.Open()
Dim rdrVen As SqlDataAdapter = New SqlDataAdapter(returnVals)
Dim DataSet As DataSet = New DataSet(returnVals.CommandText)
rdrVen.Fill(DataSet)
recreturned = DataSet.Tables(0).Rows.Count
DataGridView1.DataSource = DataSet.Tables(0)
Windows.Forms.Cursor.Current = Cursors.Default
Me.ToolStripStatusLabel1.Text = "Returned " & DataSet.Tables(0).Rows.Count & " records."
GetValues = True
oSQLConn.Dispose()
'Set the datagird null values to empty strings
Call SetIsNullStringsToEmpty(DataSet)
Catch ex As Exception
Windows.Forms.Cursor.Current = Cursors.Default
Select Case Err.Number
Case 5
MsgBox("Could not establish a connection to the database." & vbCrLf & "Record this informaiton and contact your computer analyst immediately!" & vbCrLf & vbCrLf & "Error: " & Err.Number, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
Case Else
MsgBox("An unknown error has occurred." & vbCrLf & "Please record this information and contact your computer analyst immediately!" & vbCrLf & vbCrLf & "Error: " & Err.Number & vbCrLf & "Description: " & Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
End Select
oSQLConn.Dispose()
Me.Close()
Me.Dispose()
Exit Function
End Try
End Function
Thanks for any help,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations