?
Solved

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

Posted on 2004-09-30
5
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
WesleySaysHi earned 1000 total points
ID: 12189005
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 1000 total points
ID: 12189402

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
ID: 12189978
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Progress
Introduction to Processes

800 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