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 8848
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: 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: 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...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |