?
Solved

Add rows with color

Posted on 2009-12-22
5
Medium Priority
?
429 Views
Last Modified: 2013-12-17
Hello,

If you look at the picture i have posted, you will see rows with different colours.
Each row color is set according to the "Protocol" column.

Now, i want to do the same thing. But i am not sure about what to use: Datagridview, listview or listbox ?

0f you could show me  some code on how to change backcolor of a row,  that would be great.

Note:
I am using winforms, C# and VS 2008.
I will add the data manually(row by row)
This image was a screenshot of Wireshark program.




ColorView.jpg
0
Comment
Question by:parabellum
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26103391
use listview, the listviewitem has backcolor and forecolor as properties that u can play with
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 26103398
for example:

ListViewItem item = new ListViewItem("Test");
item.UseItemStyleForSubItems = false;
item.SubItems.Add("Text", Color.Black, Color.Red, new Font(...));

check http://www.codeproject.com/KB/list/aa_listview.aspx for code source
0
 

Author Comment

by:parabellum
ID: 26103738
Ok i create a listwindows1 and use the code below:

 ListViewItem item = new ListViewItem("Test");
            listView1.View = View.Details;
            item.UseItemStyleForSubItems = false;
            item.SubItems.Add("Text", Color.Black, Color.Red, new Font("Arial",12));
            listView1.Items.Add(item);


But i do not see any color changes.
I have no idea about why i can not see the color changes.
0
 

Author Comment

by:parabellum
ID: 26103763
Ah i have finally done it.
Thanks :)
0
 
LVL 7

Expert Comment

by:keustermans
ID: 26103775
Hi there,

You can do this in a Gridview.  You just need to hook up the RowDataBound Event:

as follows:

protected void Page_Load(object sender, EventArgs e)
{
    GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
}
 
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        // Check the Value you need to refine this to handle multiple values
        if(e.Row.Cells[4].Text = "SSDP")
        {
                e.Row.DefaultCellStyle.BackColor = Color.LightGreen
        }
 
    }
}
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

864 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