none
Listview DataBound - How to change a COLUMN color and size in a listivew (Not the complete ROW) RRS feed

  • Question

  • The following code change the complete row in a listivew. How to I change only one column in a listivew row?

    If status IsNot Nothing AndAlso status.Text = "????" Then
                    ' Then find the row, and paint it red
                    Dim row = CType(e.Item.FindControl("row"), HtmlTableRow)
                    row.Attributes.Add("style", "color: red !important")
    End If


    ecb

    Monday, June 26, 2017 12:10 AM

All replies

  • The following code change the complete row in a listivew. How to I change only one column in a listivew row?

    If status IsNot Nothing AndAlso status.Text = "????" Then
                    ' Then find the row, and paint it red
                    Dim row = CType(e.Item.FindControl("row"), HtmlTableRow)
                    row.Attributes.Add("style", "color: red !important")
    End If


    ecb

    Hi

    Here is some code I have in a larger project. In this case I change a selected column BackColor, ForeColor and Font. LV being my ListView and Col being selected column index.

       Dim col As Integer = 4
       For i As Integer = 0 To LV.Items.Count - 1
           With LV
               .Items(i).UseItemStyleForSubItems = False
               If .Items(i).SubItems.Count >= col Then
                   .Items(i).SubItems(col).BackColor = Color.Red
                   .Items(i).SubItems(col).ForeColor = Color.White
                   .Items(i).SubItems(col).Font = New Font(LV.Items(i).SubItems(col).Font, FontStyle.Bold)
               End If
           End With
       Next


    Regards Les, Livingston, Scotland



    • Edited by leshay Monday, June 26, 2017 12:50 AM
    Monday, June 26, 2017 12:44 AM
  • How to I change only one column in a listivew row?

    Do you mean a Windows Forms control
    https://msdn.microsoft.com/en-us/library/system.windows.forms.listview(v=vs.110).aspx

    or a WEBControl?
    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview(v=vs.110).aspx

    What is a row or a column for a Windows Forms ListView Control depends on the view.  For instance, if you are viewing the listview in Details mode then a row is a listview item and its subitems.  In that case you would set a property (eg, BackColor, ForeClor) of the ListViewItem or ListViewSubItem that corresponds to the row and item or subitem that you want to highlight.

    If you are viewing it differently or if you are viewing a different control then the procedure will be different.

    Monday, June 26, 2017 1:04 AM
  • Hi EdCal,

    If you want to change only one column in listview row, You could need to set the BackColor of each subitem in that column. Make sure that the item's UseItemStyleForSubItems property is set to False.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 26, 2017 3:11 AM
  • I am sorry, I did not mention this is a Web application and I am attempting to change the column size and color in the text in the ListView DATABOUND section in a VB application.  I reviewed the links but I do not see the databound and how to change a attibritute of a column.   Any example would be appreciated.

    ecb

    Monday, June 26, 2017 3:29 AM
  • I am sorry, I did not mention this is a Web application

    Questions relating to ASP.Net should be asked at ASP.Net forums (ASP and VB for MVC)

    Monday, June 26, 2017 4:14 AM