473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Workmate
{
public class MyListView : ListView
{
public MyListView()
{

}
protected override void OnPaint(PaintEventArgs e)
{

SolidBrush drawBrush = new SolidBrush(BackColor); //Use the ForeColor property
e.Graphics.DrawRectangle(new Pen(drawBrush), 0, 0, Width, Height);

}
protected override void OnEnabledChanged(EventArgs e)
{

Refresh();

}
protected override void OnItemCheck(ItemCheckEventArgs ice)
{
if (Enabled == true)
{
base.OnItemCheck(ice);
}


}

protected override void OnColumnClick(ColumnClickEventArgs e)
{
base.OnColumnClick(e);
Refresh();
}

protected override void OnMouseDown(MouseEventArgs e)
{
if (Enabled == true)
{
base.OnMouseClick(e);
}
else

}



}
}
Feb 15 '08 #1
3 1518
May be your onPaint event is happening before the Refresh(). So you loose the background color
Feb 15 '08 #2
May be your onPaint event is happening before the Refresh(). So you loose the background color


Sanat Palia
Feb 15 '08 #3
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?
Feb 21 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
1
by: plmanikandan | last post by:
Hi, I have a listview with items,subitems.I tems and subitems are added as below listView1.View = View.Details; listView1.Columns.Add("Column 1", 100,HorizontalAlignment.Center);...
2
by: polocar | last post by:
Hello, I'm developing a C# program using Visual Studio 2005 Professional Edition. In the main form I have inserted a ListView control that is populated in a different way depending on the item...
0
by: svx | last post by:
Hello, I am painting individual rows in a ListView control with different colors, depending on state. I am also using a SmallImageList in Detail view. When I set the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.