how to move a label on columnwidth changeevent in listview --C# windows form

Posted on 2007-11-17
Last Modified: 2013-12-17
how to move a label on columnwidth changeevent in listview --C# windows form

i had a list view i want the sieze to be of 12 but the column name should be of 8 so i placed a label on that with 8 font but when ever i move the coloumn the label should also be moved
so can any one tell me how to move the label in columnwidth change event
Question by:kranthi4uonly
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20306100
Doesn't seems like a clean solution, maybe you can try to derive a custom listview control and override the OnDrawColumnHeader method.
Here is an example where text alignment in header is changed, but you can modify to draw with a smaller font:

Author Comment

ID: 20310411
hi  ihad developed the user defined control as u said the code follows like this
private void UserControl1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
            using (StringFormat sf = new StringFormat())
                // Draw the header text.
                using (Font headerFont = new Font("Microsoft Sans Sarif", 8, FontStyle.Regular))
                    e.Graphics.DrawString(e.Header.Text, headerFont,
                        Brushes.Black, e.Bounds, sf);

but my problem is when iam inheriting it and trying to add items from list box i cannot see any items in list view but ican see the scroll ball growing when i click the button the code for insert is as follows

private void button1_Click(object sender, EventArgs e)
 string t = listBox1.SelectedItem.ToString();
            ListViewItem lv = new ListViewItem(t);
            userControl11.Items.AddRange(new ListViewItem[] { lv });
can u tell me the reason please
LVL 55

Accepted Solution

Jaime Olivares earned 500 total points
ID: 20310467

Author Comment

ID: 20311075
excellent but can't i click on the column for sorting
right now i can't click the column

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question