Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-30
5
Medium Priority
?
321 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress

618 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