You must Sign In to post a response.
  • Category: .NET

    How to Set Coloring and Font Style and Alignment etc


    I have Design ListView in C# windows Application.
    How to Set Coloring and Font Style and Alignment etc in particular cell

    My Data this

    Name Empno Status
    aa 100 OK
    bb 200 NOTOK status is which is ok that cell value font color with bold need . How will do this
    2.when i selected row i need coloring the selected row in listview.
  • #767641
    you can set different font size and style to each listview items, see below snippet

    private void InitializeListView()

    // Set the Location, View and Width properties for the
    // ListView object.
    myListView = new ListView();
    myListView.Location = new System.Drawing.Point(20, 20);
    myListView.Width = 250;

    // The View property must be set to Details for the
    // subitems to be visible.
    myListView.View = View.Details;

    // Each SubItem object requires a column, so add three columns.
    this.myListView.Columns.Add("Key", 50, HorizontalAlignment.Left);
    this.myListView.Columns.Add("A", 100, HorizontalAlignment.Left);
    this.myListView.Columns.Add("B", 100, HorizontalAlignment.Left);

    // Add a ListItem object to the ListView.
    ListViewItem entryListItem = myListView.Items.Add("Items");

    // Set UseItemStyleForSubItems property to false to change
    // look of subitems.
    entryListItem.UseItemStyleForSubItems = false;

    // Add the expense subitem.
    ListViewItem.ListViewSubItem expenseItem =

    // Change the expenseItem object's color and font.
    expenseItem.ForeColor = System.Drawing.Color.Red;
    expenseItem.Font = new System.Drawing.Font(
    "Arial", 10, System.Drawing.FontStyle.Italic);

    // Add a subitem called revenueItem
    ListViewItem.ListViewSubItem revenueItem =

    // Change the revenueItem object's color and font.
    revenueItem.ForeColor = System.Drawing.Color.Blue;
    revenueItem.Font = new System.Drawing.Font(
    "Times New Roman", 10, System.Drawing.FontStyle.Bold);

    // Add the ListView to the form.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767642

    your code not working. I need windows application C# particular cell text fore color changed in runtime.
    which is status=OK

    Name : Dotnet Developer-2015

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767655

    Try below sample

    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    var dataItem = e.Item as ListViewDataItem;
    if (dataItem != null)
    string Status = (string)ListView1.DataKeys[dataItem.DisplayIndex]["Status"];
    if (Status == "OK")
    e.item.attributes.add("style", "background-color: red");

    Hope this helps you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #767658

    check My question I mention like this I have Design ListView in C# windows Application.

    I need only Windows application. ItemDataBound Event only Web . can you send corresponding
    windows application.

    Name : Dotnet Developer-2015

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767669
    Hai Prasad,
    You need to first need to make the default style for the subitem to be false and then you can apply the other styles like:

    ListView1.Items[0].UseItemStyleForSubItems = false;
    ListView1.Items[0].SubItems[1].ForeColor = Color.Blue;

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

Sign In to post your comments