Solved

How to apply color in a cell through vb.net coding

Posted on 2004-09-30
5
306 Views
Last Modified: 2010-04-17
How to change Backcolor / Forecolor of single cell of listView during run time in Vb.net.
0
Comment
Question by:subbiahs
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
WesleySaysHi earned 250 total points
Comment Utility
The line:
cell.BackColor = System.Drawing.Color.DarkOliveGreen
changes the background colour to dark olive green. Change the foreground colour in similar way.

Wesley

0
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 250 total points
Comment Utility

If you want to change color of Single Cell you'll need to do this at DataBinding time in ItemDataBound event, here's C# code for the same:

----------------------------------------------------------------------------------------------------------------------------------
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
      switch( e.Item.ItemType )
         {
            case ListItemType.Item:
            case ListItemType.AlternatingItem:
                  e.Item.Cells[0].BackColor = Color.Red;      
                  e.Item.Cells[0].ForeColor = Color.White;      
            break ;
             }
  }
----------------------------------------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 5

Expert Comment

by:WesleySaysHi
Comment Utility
you still have problems?
Then I give you both lines you must use at runtime in VB.NET:

cell.BackColor = System.Drawing.Color.DarkOliveGreen
cell.ForeColor = System.Drawing.Color.DarkOliveGreen

One interesting thing you can do is to let the user change these colors during program execution: add a ColorDialog control to the form, set its Color property to the color you want it to have initially selected (for example dark olive green), then call the control's ShowDialog method. If the method returns DialogResult.OK, change the back color, or the forecolor.

Private Sub btnPickColor_Click(ByVal sender As _
    System.Object, _
 ByVal e As System.EventArgs) Handles btnPickColor.Click
    dlgColor.Color = Me.BackColor
    If dlgColor.ShowDialog() = DialogResult.OK Then
        btnPickColor.BackColor = dlgColor.Color
        Me.BackColor = dlgColor.Color
    End If
End Sub
 
Wesley
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now