Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3805838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:44:28+00:00 2026-05-19T14:44:28+00:00

I have face resize problem of listview columns. If you anchor/docking the listview to

  • 0

I have face resize problem of listview columns. If you anchor/docking the listview to normal winform than the listview anchor or docking works well. I mean listview will resize and fit to winforms as winforms maximized but the columns you have designed on it which is not resize with listview.

My question is : Is there any way to resize the columns of listview with listview to fit winform size?.

Listview Design Code:

 private void Form1_Load(object sender, EventArgs e)
    {

        listView1.View = View.Details;
        listView1.LabelEdit = true;
        listView1.BackColor = Color.GreenYellow;
        listView1.Columns.Add("Date", 100, HorizontalAlignment.Left);
        listView1.Columns.Add("TransID", 50, HorizontalAlignment.Left);
        listView1.Columns.Add("voucher", 100, HorizontalAlignment.Right);
        listView1.Columns.Add("particulars", 300, HorizontalAlignment.Left);
        listView1.Columns.Add("deposit", 100, HorizontalAlignment.Right);
        listView1.Columns.Add("withdrawal", 100, HorizontalAlignment.Right);

        string connstr = "server=.;initial catalog=DataBase;uid=UID;pwd=PWD";
        SqlConnection con = new SqlConnection(connstr);
        con.Open();
        listView1.Items.Clear();
        listView1.Refresh();
        string sql = "select date=convert(varchar,date,103),transID,max(particulars)as particulars,sum(deposit)as deposit,sum(withdrawal) as withdrawal,voucher from debank group by date,transID,voucher";
        SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        DataTable dt = ds.Tables[0];

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];
            ListViewItem lvi = new ListViewItem(dr["date"].ToString());
            lvi.SubItems.Add(dr["transID"].ToString());
            lvi.SubItems.Add(dr["voucher"].ToString());
            lvi.SubItems.Add(dr["particulars"].ToString());
            lvi.SubItems.Add(dr["deposit"].ToString());
            lvi.SubItems.Add(dr["withdrawal"].ToString());
            listView1.Items.Add(lvi);
            listView1.FullRowSelect = true;

        }

        SizeLastColumn(listView1);


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:44:29+00:00Added an answer on May 19, 2026 at 2:44 pm
    1. Programatic one. You’ll have to maintain it in code.
    2. You can adjust last column size in your listview so that it would be automatically resized.
      Net sample:

    In a ListView control, with the View
    property set to Details, you can
    create a multi-column output.
    Sometimes you will want the last
    column of the ListView to size itself
    to take up all remaining space. You
    can do this by setting the column
    width to the magic value -2.

    In the following example, the name of
    the ListView control is lvSample:

    [c#]
    private void Form1_Load(object sender, System.EventArgs e)
    {
        SizeLastColumn(lvSample);
    }
    
    private void listView1_Resize(object sender, System.EventArgs e)
    {
        SizeLastColumn((ListView) sender);
    }
    
    private void SizeLastColumn(ListView lv)
    {
        lv.Columns[lv.Columns.Count - 1].Width = -2;
    }
    

    EDIT:

    Programaticaly you can do that with own implemented algorithm. The problem is that the list view does not know what of the columns you would like to resize and what not. So you’ll have in the resize method (or in resizeEmd method) to specify all the columns size change. So you calculate all the width of the listview then proportionaly divide the value between all columns.
    Your columns width is multiple to 50. So you have the whole listview width of 15*х (x=50 in default state. I calculated 15 value based on number of your columns and their width) conventional units. When the form is resized, you can calculate new x = ListView.Width/15 and then set each column width to needed value, so

    private void SizeLastColumn(ListView lv)
    {
     int x = lv.Width/15 == 0 ? 1 : lv.Width/15;
     lv.Columns[0].Width = x*2; 
     lv.Columns[1].Width = x;
     lv.Columns[2].Width = x*2;
     lv.Columns[3].Width = x*6;
     lv.Columns[4].Width = x*2;
     lv.Columns[5].Width = x*2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with CSS3 property for using my own fonts @font-face. In
we have a classical 3-tier-architecture application. Now we face a little problem and we
I have face a problem that all my app in my iphone is not
Let's we have std::vector <std::vector <unsigned short int>> face; face.resize(nElm); Its OK to resize()
I have problem with the get the listview item when click listitem. I Got
I Have More than One Face Book ApplicationUsing the same Solution what i need
I have used the pScene.detachChild(face); to remove Sprite from scene. It hide face object
I have refereed old questions and found that people face many issues after installing
I face some layout differences in IE and in Chrome. I have searched Stack
I have a simple situation here. lets face html code first => <form name=geoKey

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.