Probelm in changing Backcolor of Listview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpfreak2007
    New Member
    • Sep 2007
    • 31

    Probelm in changing Backcolor of Listview

    Hello All,,,
    I am using Following code to change the back color of list view. I don't want the Windows default gray color when Listview is Enable false.so I have crated one class by inheriting the ListView and override some method. OnEnableChange event i just call Refresh. so it paint the background with the color i specified. and in column click event i am sorting the column.. when i click on the column header back color change to widows default Gray. I don't know whats wrong.???

    using System;
    using System.Collecti ons.Generic;
    using System.Text;
    using System.Windows. Forms;
    using System.Drawing;
    namespace Workmate
    {
    public class MyListView : ListView
    {
    public MyListView()
    {

    }
    protected override void OnPaint(PaintEv entArgs e)
    {

    SolidBrush drawBrush = new SolidBrush(Back Color); //Use the ForeColor property
    e.Graphics.Draw Rectangle(new Pen(drawBrush), 0, 0, Width, Height);

    }
    protected override void OnEnabledChange d(EventArgs e)
    {

    Refresh();

    }
    protected override void OnItemCheck(Ite mCheckEventArgs ice)
    {
    if (Enabled == true)
    {
    base.OnItemChec k(ice);
    }


    }

    protected override void OnColumnClick(C olumnClickEvent Args e)
    {
    base.OnColumnCl ick(e);
    Refresh();
    }

    protected override void OnMouseDown(Mou seEventArgs e)
    {
    if (Enabled == true)
    {
    base.OnMouseCli ck(e);
    }
    else

    }



    }
    }
  • sanatpalia
    New Member
    • Feb 2008
    • 10

    #2
    May be your onPaint event is happening before the Refresh(). So you loose the background color

    Comment

    • sanatpalia
      New Member
      • Feb 2008
      • 10

      #3
      May be your onPaint event is happening before the Refresh(). So you loose the background color


      Sanat Palia

      Comment

      • phpfreak2007
        New Member
        • Sep 2007
        • 31

        #4
        Originally posted by sanatpalia
        May be your onPaint event is happening before the Refresh(). So you loose the background color


        Sanat Palia

        I dont know the exact flow of event. that which event will first and which after that..if on paint is happning before refresh(). how to overcome that?

        Comment

        Working...