Horizontal scroll not working with OwnerDraw (List box)
-
:(( hi friends i am working with listbox The problem :Horizontal scroll is not working as expected when i use OwnerDraw mode MeasureItemEventHandler please help regards and thank you in advance /**************** code ************/ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication1 { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { InitializeOwnerDrawnListBox(); } internal System.Windows.Forms.ListBox ListBox1; private void InitializeOwnerDrawnListBox() { this.ListBox1 = new System.Windows.Forms.ListBox(); // Set the location and size. ListBox1.Location = new Point(20, 20); ListBox1.Size = new Size(100, 100); // Populate the ListBox.ObjectCollection property // with several strings, using the AddRange method. this.ListBox1.Items.AddRange(new object[]{"System.Windows.Forms", "System.Drawing", "System.Xml", "System.Net", "System.Runtime.Remoting", "System.Web
-
:(( hi friends i am working with listbox The problem :Horizontal scroll is not working as expected when i use OwnerDraw mode MeasureItemEventHandler please help regards and thank you in advance /**************** code ************/ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication1 { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { InitializeOwnerDrawnListBox(); } internal System.Windows.Forms.ListBox ListBox1; private void InitializeOwnerDrawnListBox() { this.ListBox1 = new System.Windows.Forms.ListBox(); // Set the location and size. ListBox1.Location = new Point(20, 20); ListBox1.Size = new Size(100, 100); // Populate the ListBox.ObjectCollection property // with several strings, using the AddRange method. this.ListBox1.Items.AddRange(new object[]{"System.Windows.Forms", "System.Drawing", "System.Xml", "System.Net", "System.Runtime.Remoting", "System.Web
-
hi, I guess you need to set the "listBox1.HorizontalScrollbar = true" property of the ListBox... and that will do the magic... regards, Aryadip. Cheers !! and have a Funky day !!
-
hi, But your code shows that the line is commented... for your ease let me point out the line with repeated "*"s... // Handle the MeasureItem event for an owner-drawn ListBox. private void ListBox1_MeasureItem(object sender, MeasureItemEventArgs e) { // Cast the sender object back to ListBox type. ListBox theListBox = (ListBox) sender; // Get the string contained in each item. string itemString = (string) theListBox.Items[e.Index]; // Split the string at the " . " character. string[] resultStrings = itemString.Split('.'); // If the string contains more than one period, increase the // height by ten pixels; otherwise, increase the height by // five pixels. if (resultStrings.Length>2) { e.ItemHeight += 10; /*********** you have commented here**********************/ //theListBox.HorizontalScrollbar = true ; /********************************************************/ } else { e.ItemHeight += 5; } e.ItemWidth +=100000 ; } and if it has still not worked... then try declaring the same when you are instantiating or rather creating the listbox... regards, Aryadip. Cheers !! and have a Funky day !!