Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
3.22/5 (2 votes)
See more:
I have implemented the following for a listview control:

C#
private void transactionGrid_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
   TextFormatFlags flags = TextFormatFlags.Left;

   using (StringFormat sf = new StringFormat())
   {
      // Store the column text alignment, letting it default
      // to Left if it has not been set to Center or Right.
      switch (e.Header.TextAlign)
      {
         case HorizontalAlignment.Center:
            sf.Alignment = StringAlignment.Center;
            flags = TextFormatFlags.HorizontalCenter;
            break;
         case HorizontalAlignment.Right:
            sf.Alignment = StringAlignment.Far;
            flags = TextFormatFlags.Right;
            break;
      }

      CultureInfo culture;
      DateTimeStyles styles;
      DateTime dateResult;

      culture = CultureInfo.CreateSpecificCulture("fr-FR");
      styles = DateTimeStyles.None;
      if (DateTime.TryParse(e.SubItem.Text, culture, styles, out
 dateResult))
      {
         sf.Alignment = StringAlignment.Far;
         Brush b;
         b = ((e.Item.Tag as Transaction).Cleared) ? Brushes.Black : Brushes.Red;
         e.Graphics.DrawString(_Globals.myDateStr(dateResult), transactionGrid.Font, b, e.Bounds, sf);
         return;
      }
      e.DrawText(flags);
   }
}

When I do this I lose the highlight on the selected line
I have FullRowSelect==true and hideslection=false

How can I do the drawsubitem and still highlight the whole row please?


[edit]Code block added[/edit]
Posted
Updated 18-Apr-15 12:24pm
v2

1 solution

Ever had a look to Canvas? This peace gives you all the stuff you Need to draw pink/green, bold &¦¦italian and much more.
 
Share this answer
 
v2
Comments
KevinBadger 19-Apr-15 8:37am    
Erm...
Being a bit dumb here but:

1. Canvas? Where is this in relation to the listview item?
2. If I can use .canvas where do I put the code? Drawsubitem relates to a subitem and I want to highlight the entire line but drawitem does not seem to get triggered?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900