Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 88
Getting the Error "User-defined type not defined" in MS Access 2013 16 82
Using Third Party DLL with Access VBA 14 51
BATCH to EXE Converter 2 68
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.

756 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