Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ListView columns show up overlapped

ListView columns show up overlapped

Scheduled Pinned Locked Moved C#
csharpwinformsgraphicsdockerhelp
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kmansari
    wrote on last edited by
    #1

    I am new to .NET in general and Windows Forms programming in particular. As a part of a bigger project, I am trying to write a test application. I have a ListView control whose number of rows and columns are determined by the user at runtime. To read the number of rows and columns, I have provided two textboxes. I have a refresh button, which when clicked, reads the number of rows and columns from the text boxes and tries to populate the ListView control. When I run the program and click on the Refresh button, it appears as if nothing has happened in response to that click. The fact, however, is that the ListView control gets populated successfully, but no data is visible because the columns somehow overlap each other. I verified this by clicking inside the ListView control and pressing "CTRL +". On doing that, the columns auto-arrange themselves and become visible. My gut feeling is that this is something really simple and stupid. Please help me out! ========================= CODE BEGINS =========================================================== using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ListViewTest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox TB_Rows; private System.Windows.Forms.TextBox TB_Columns; private System.Windows.Forms.Label LABEL_Rows; private System.Windows.Forms.Button BTN_Refresh; private System.Windows.Forms.ListView LV_Data; private System.Windows.Forms.Label LABEL_Columns; private System.Windows.Forms.TextBox TB_BaseString; private System.Windows.Forms.Label LABEL_BaseString; private int m_iColumnCount; private int m_iRowCount; private string m_szBaseString; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// 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

    S 1 Reply Last reply
    0
    • K kmansari

      I am new to .NET in general and Windows Forms programming in particular. As a part of a bigger project, I am trying to write a test application. I have a ListView control whose number of rows and columns are determined by the user at runtime. To read the number of rows and columns, I have provided two textboxes. I have a refresh button, which when clicked, reads the number of rows and columns from the text boxes and tries to populate the ListView control. When I run the program and click on the Refresh button, it appears as if nothing has happened in response to that click. The fact, however, is that the ListView control gets populated successfully, but no data is visible because the columns somehow overlap each other. I verified this by clicking inside the ListView control and pressing "CTRL +". On doing that, the columns auto-arrange themselves and become visible. My gut feeling is that this is something really simple and stupid. Please help me out! ========================= CODE BEGINS =========================================================== using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ListViewTest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox TB_Rows; private System.Windows.Forms.TextBox TB_Columns; private System.Windows.Forms.Label LABEL_Rows; private System.Windows.Forms.Button BTN_Refresh; private System.Windows.Forms.ListView LV_Data; private System.Windows.Forms.Label LABEL_Columns; private System.Windows.Forms.TextBox TB_BaseString; private System.Windows.Forms.Label LABEL_BaseString; private int m_iColumnCount; private int m_iRowCount; private string m_szBaseString; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// 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

      S Offline
      S Offline
      Skynyrd
      wrote on last edited by
      #2

      private void CreateColumns () { // Create the "Item" column first //this.LV_Data.Columns.Add ("Item Column", -2, HorizontalAlignment.Left); // Now create the data columns for (int i=0; i < m_iColumnCount; i++) this.LV_Data.Columns.Add ("Column " + i.ToString(), -2 * (i+1), HorizontalAlignment.Left); } ur setting the width of your columns to -2*(i+1) which will always be <0. I dont understand what ur trying to do here, but if u just change the width to a fixed one (70), everything works fine.

      K 1 Reply Last reply
      0
      • S Skynyrd

        private void CreateColumns () { // Create the "Item" column first //this.LV_Data.Columns.Add ("Item Column", -2, HorizontalAlignment.Left); // Now create the data columns for (int i=0; i < m_iColumnCount; i++) this.LV_Data.Columns.Add ("Column " + i.ToString(), -2 * (i+1), HorizontalAlignment.Left); } ur setting the width of your columns to -2*(i+1) which will always be <0. I dont understand what ur trying to do here, but if u just change the width to a fixed one (70), everything works fine.

        K Offline
        K Offline
        kmansari
        wrote on last edited by
        #3

        Thanks a lot. :) :) I got the -2 from a Microsoft sample and then while playing around with the code, I added that (i+1) part. Here's the sample I am talking about: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewlistviewitemcollectionclassaddrangetopic.asp[^] Thanks a lot again.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups