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
Solved

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

Posted on 2004-09-30
5
313 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
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 250 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 109
VB6 Compile Compatibility Issue 4 115
What are programming codes and how do they work? 7 103
Select specific duplicate row based on specific criteria 4 56
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…
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…

840 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