I have used ListView in my Form. I have set OwnerDraw = true. And I have the DrawItem Function as - private void listView1_DrawItem(object sender,
-
DrawListViewItemEventArgs e)
-
{
-
if (e.Item.Checked)
-
ControlPaint.DrawCheckBox(e.Graphics, 0, e.Bounds.Top + 1, 15, 15,
-
ButtonState.Flat | ButtonState.Checked);
-
else
-
ControlPaint.DrawCheckBox(e.Graphics, 0, e.Bounds.Top + 1, 15, 15, ButtonState.Flat);
-
-
Rectangle rect = new Rectangle(e.Bounds.X + 23, e.Bounds.Y + 1, e.Bounds.Width, e.Bounds.Height);
-
if ((e.State & ListViewItemStates.Selected) != 0)
-
{
-
// Draw the background and focus rectangle for a selected item.
-
e.Graphics.FillRectangle(Brushes.AliceBlue, rect);
-
e.DrawFocusRectangle();
-
}
-
else
-
{
-
// Draw the background for an unselected item.
-
using (LinearGradientBrush brush =
-
new LinearGradientBrush(rect, Color.White,
-
Color.White, LinearGradientMode.Horizontal))
-
{
-
e.Graphics.FillRectangle(brush, rect);
-
}
-
}
-
-
// Draw the item text for views other than the Details view.
-
if (listView1.View != View.Details)
-
{
-
e.DrawText();
-
}
-
}
My problem is when I scroll the horizontal scrollbar (NOT with vertical scrollbar) checkboxes are not displaying correctly or drawing improperly (sometimes hidden and appears after selecting listitem). Why is this happening? Is it because of Graphics use? How can I get rid of this problem? Please help me.
7 8838
Hi,
Is it your intention that the checkbox scrolls off screen to the left, or that it remains visible when using the horizontal scrollbar and that the text just disappears underneath it?
When I scroll the horizontal scroll bar.....It draw the Checkboxes improperly.
Sometimes full chekbox sometime half......Sometime location change.
@prpradip
Yes, I tested your code and I can see what you mean. What you need to change depends on what you want the checkbox to do.
Do you want it scroll cleanly, or remain fixed at the edge of the listview?
If you want it to scroll with the text change the first couple of lines of code to: -
if (e.Item.Checked)
-
ControlPaint.DrawCheckBox(e.Graphics, e.Bounds.X, e.Bounds.Top + 1, 15, 15, ButtonState.Flat | ButtonState.Checked);
-
else
-
ControlPaint.DrawCheckBox(e.Graphics, e.Bounds.X, e.Bounds.Top + 1, 15, 15, ButtonState.Flat);
-
-
No I want it to stay where it is i.e, when I scroll horizontal scroll bar to Right it should remains where it is and when I scroll horizontal scroll bar to left, checkboxes should display properly.
Ok, I've spent a good half-hour looking at this but it looks like one of those things that isn't going to be easy. I remember trying to do something fairly similar myself with the listview a few months back.
If I recall correctly I couldn't get it working in the DrawItem event unless I used CreateGraphics() to get a new graphics object and painted onto that instead. I didn't like that solution, so I started overriding WndProc, which almost yielded the results I wanted, but became far to much work to maintain for what I was trying to do. I'm sure I've still got that code around somewhere but cannot locate it at the moment.
In short it was taking more time than it was worth to get it the way I wanted it. In the end I gave up and found an alternative solution. Sorry I can't be more help.
Maybe there is an alternative way to acheive the results you want. Is a CheckListBox control no use to you?
Yes I need checkbox. BTW what is the solution u do? can u supply it?
@prpradip
I'd use a checked list box.
Edit: If you're using Visual Studio you should find it it your control toolbox.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Richard |
last post by:
Hello. In VB .NET I have a class derived from ListView like this:
Public Class ListViewSorted
Inherits System.Windows.Forms.ListView
'code to make this ListViewSorted class sortable...
End...
|
by: Andre |
last post by:
Hi,
I have a strange problem when i try to display my data on a web page.
Everything's fine until i try to display a Date Value.
If i try to display this, no problem :
obj("data1")...
|
by: andrewcw |
last post by:
I have a simple winform with the following code.
But although I can read back the info, the display fails
to provide the text or the cell background color changes.
private void ListViewBroke()...
|
by: Jonas Knaus |
last post by:
Hello
Is it not possible to have more than one checked item on one line on a
ListView?
I only figured out how to have one checkBox but i would like have a checkBox
on every Column. Is this...
|
by: tim cummings via .NET 247 |
last post by:
I am writing a program that interfaces with a cars pcm via theserial port and recieves data (such as rpm) at an interval, oflets say 1 second, and then formats it. The problem is, I wouldlike to...
|
by: tlyczko |
last post by:
I have an odd display problem with Access 2003 on XP SP2, latest
patches, etc.
I am working on a not large DB with several forms and <100 records per
table, it is still in development.
...
|
by: tmda |
last post by:
I'm using OwnerDraw for some customization in my ListView - adding
color to item backgrounds. I'm using the ListView specifically for
it's OwnerDraw capability. I originally was using the...
|
by: pssraju |
last post by:
Hi,
I am having applet display problem on my PC and the same thing working fine on some of my colleagues PC's. When I cross checked content through view source its exactly same on both the PC's....
|
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= |
last post by:
Hi,
i know how to work with the owner draw mode in
the ListView-Class, but how do i draw the last three
dots in a column if the text exceeds the columns width?
To make it clear, i am talking...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |