3
Contributors
12
Replies
13
Views
8 Years
Discussion Span
Last Post by serkan sendur
Featured Replies
  • 1
    sknake 1,622   8 Years Ago

    Hey now... you slacked off on that last 10 day one. I think you made it 3 days :( Read More

  • 1
    sknake 1,622   8 Years Ago

    Sorry buddy.. you have me on this. I have never used a ListView and i'm not seeing a way to about this :( Read More

0

If you click on the liste view, in the properties menu, you can set "Allow Column Reorder" to true. Thats a good place to start.

0

an idea came to my mind but i dont think it is quite smart.
i can remove the items and get the reference of the removed item and then add the item using AddAt method. i will try that.

0

i am flabergasted :(
you used to be a hardworker when it came to posting some useful code snippets to my questions :(

0

I will, I promise :P

It is a Friday evening and i'm having a few drinks before I call it a night. I will take a look at this in the morning. Take the night off! :)

0

ok that is the deal, then i will increase your reputation points by 5 as well as one more solved threads :D

0

here is the solution :

Form1.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProgrammaticallyReorderListview
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		ColumnHeader ch1;
		private void Form1_Load(object sender, EventArgs e)
		{
			ListViewItem item1 = listView1.Items.Add("item1");
			item1.SubItems.Add("subitem1");
			item1.SubItems.Add("subitem2");
			ListViewItem item2 = listView1.Items.Add("item2");
			item2.SubItems.Add("subitem1");
			item2.SubItems.Add("subitem2");

			ch1 = listView1.Columns.Add("column1");
			listView1.Columns.Add("column2");
			listView1.Columns.Add("column3");
		}
		private int columnIndex = 1;
		private void button1_Click(object sender, EventArgs e)
		{
			columnIndex = columnIndex % 3;
			listView1.Columns.Remove(ch1);
			listView1.Columns.Insert(columnIndex, ch1);
			columnIndex++;
		}
	}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.