Home All Groups Group Topic Archive Search About

DataGridView row background color

Author
26 Jun 2006 4:06 PM
martin1
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!

Author
27 Jun 2006 5:23 PM
Jack
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


Show quoteHide quote
> 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!
>
Author
27 Jun 2006 7:33 PM
martin1
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

Show quoteHide quote
"Jack" wrote:

> 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
>
>
> > 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!
> >
>
>
>
Author
27 Jun 2006 7:41 PM
Brian Tkatch
martin1 wrote:
Show quoteHide quote
> 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
>
> "Jack" wrote:
>
> > 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
> >
> >
> > > 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!
> > >
> >
> >
> >

If the datasource is a datatable.

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

B.
Author
27 Jun 2006 9:23 PM
martin1
Thank you. Brian,

how about datasource is DataGridView? which is pupulated from dataset

Show quoteHide quote
"Brian Tkatch" wrote:

>
> martin1 wrote:
> > 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
> >
> > "Jack" wrote:
> >
> > > 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
> > >
> > >
> > > > 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!
> > > >
> > >
> > >
> > >
>
> If the datasource is a datatable.
>
> Table.Columns(Column_Name).ColumnMapping() = MappingType.Hidden
>
> B.
>
>
Author
27 Jun 2006 9:33 PM
martin1
I figure now

DataGridView.Columns(colume_name).Visible = False

Show quoteHide quote
"martin1" wrote:

> Thank you. Brian,
>
> how about datasource is DataGridView? which is pupulated from dataset
>
> "Brian Tkatch" wrote:
>
> >
> > martin1 wrote:
> > > 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
> > >
> > > "Jack" wrote:
> > >
> > > > 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
> > > >
> > > >
> > > > > 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!
> > > > >
> > > >
> > > >
> > > >
> >
> > If the datasource is a datatable.
> >
> > Table.Columns(Column_Name).ColumnMapping() = MappingType.Hidden
> >
> > B.
> >
> >
Author
28 Jun 2006 4:33 PM
Brian Tkatch
martin1 wrote:
Show quoteHide quote
> Thank you. Brian,
>
> how about datasource is DataGridView? which is pupulated from dataset
>
> "Brian Tkatch" wrote:
>
> >
> > martin1 wrote:
> > > 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
> > >
> > > "Jack" wrote:
> > >
> > > > 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
> > > >
> > > >
> > > > > 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!
> > > > >
> > > >
> > > >
> > > >
> >
> > If the datasource is a datatable.
> >
> > Table.Columns(Column_Name).ColumnMapping() = MappingType.Hidden
> >
> > B.
> >
> >

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.