DataGridView row background color

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, all,

Is there any way to change DataGridView row color based on different row
data? for example, if row data in first column = 1, it is yellow, if it is 2,
it is blue, if 3 it is white. That means how to loop DataGridData to get row
data, then based on the different data to change row background color?

Thanks in advance!
 
Hello martin1,
after some modifications this will do...

Dim CountR As Integer

For CountR = 0 To GridView1.Rows.Count - 1
Select Case GridView1.Rows(CountR).Cells(1).Text
Case "Austria" : GridView1.Rows(CountR).BackColor = Drawing.Color.Yellow
Case "Brazil" : GridView1.Rows(CountR).BackColor = Drawing.Color.Violet
Case "Belgium" : GridView1.Rows(CountR).BackColor = Drawing.Color.Aqua
Case Else : GridView1.Rows(CountR).BackColor = Drawing.Color.Coral
End Select

Next


Jack
 
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks
 
martin1 said:
Thank you. Jack

another question is do yuo know how to remove some columns from
DataGridView? whcih feature and function is used for this? Thanks

If the datasource is a datatable.

Table.Columns(Column_Name).ColumnMapping() = MappingType.Hidden

B.
 
martin1 said:
Thank you. Brian,

how about datasource is DataGridView? which is pupulated from dataset

Then go up first. :)

MyDataGridView.DataSource.Table.Columns(Column_Name).ColumnMapping() =
MappingType.Hidden

Just like every DataTable has a link to it's DefaultView every DataView
has a link to it's (parent) Table.

BTW, if you want context-sensitive help to appear, you have to tell the
editor whatr the DataSource is, since it otherwise will not know (since
it can be a DataSet, DataTable, DataView...), and this is (one of the
things) done via CType.

CType(MyDataGridView.DataSource,
DataView).Table.Columns(Column_Name).ColumnMapping() =
MappingType.Hidden


B.
 
Back
Top