searchsanjaysharma
asked on
how to make the datagridview row as red color if the cell value contains D
I am having the following code,
I want if in any row the cell value for a particular column in D then the row should be marked as red ie the backcolor
Try
con = New SqlConnection("Data Source=xxx.xxx.xxx.xxx;Ini tial Catalog=cusem2;User Id=sa;Password=tomato!@#$o tamot")
s1 = "select UID,Sname as 'Name',fname as 'Father',IMS from mstmassstudents where institute='" & CType(cmbinstitutes.Select edItem, DataRowView)("institute"). ToString() & "' and course='" & CType(cmbcourses.SelectedI tem, DataRowView)("course").ToS tring() & "' and subjectcode='" & CType(cmbsubjectcodes.Sele ctedItem, DataRowView)("subjectcode" ).ToString () & "' order by 1"
If (con.State = ConnectionState.Closed) Then
con.Open()
End If
da1 = New SqlDataAdapter(s1, con)
dt1 = New DataTable()
da1.Fill(dt1)
DataGridView1.DataSource = dt1
DataGridView1.Visible = True
DataGridView1.AllowUserToA ddRows = False
For Each row As DataGridViewRow In DataGridView1.Rows
Dim obj(row.Cells.Count - 1) As Object
If (row.Cells(3).Value = "D") Then
row.ReadOnly = True
End If
Next
Catch ex As Exception
MsgBox("Error occured : " & ex.ToString())
Finally
con.Close()
End Try
I want if in any row the cell value for a particular column in D then the row should be marked as red ie the backcolor
Try
con = New SqlConnection("Data Source=xxx.xxx.xxx.xxx;Ini
s1 = "select UID,Sname as 'Name',fname as 'Father',IMS from mstmassstudents where institute='" & CType(cmbinstitutes.Select
If (con.State = ConnectionState.Closed) Then
con.Open()
End If
da1 = New SqlDataAdapter(s1, con)
dt1 = New DataTable()
da1.Fill(dt1)
DataGridView1.DataSource = dt1
DataGridView1.Visible = True
DataGridView1.AllowUserToA
For Each row As DataGridViewRow In DataGridView1.Rows
Dim obj(row.Cells.Count - 1) As Object
If (row.Cells(3).Value = "D") Then
row.ReadOnly = True
End If
Next
Catch ex As Exception
MsgBox("Error occured : " & ex.ToString())
Finally
con.Close()
End Try
ASKER
This doest work as DefaultCellstyle is not there.
I am sorry . (FROM MOBILE)
Try style.BackColor
Yiannis
Try style.BackColor
Yiannis
ASKER
Not working
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tx
Try
Open in new window