Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView in a single column

Status
Not open for further replies.

McKaulick

Programmer
Oct 24, 2002
35
0
0
AR
Hello,

I have a ListView that display the content of a folder. In this folder, I have 6 files. The files are beign displayed 3 per lines and I have 2 lines, I would like to have an Item per line and 6 lines (One column). I tried many things, but for some reason, it does not work. Here's the code.

foreach ( FileInfo file in fileArray )
{
lstFile.Items.Add (file.Name+"\r\n");
}

Thanks for any help
 
Code:
this.listView1 = new System.Windows.Forms.ListView();
this.listView1 = new ListView();
//..
private void FormatListView()
{

	this.listView1.View = View.Details;
	// Add columns and set their text.
	this.listView1.Columns.Add(new ColumnHeader());
	this.listView1.Columns[0].Text = "Column 1";
	this.listView1.Columns[0].Width = 100;

}
private void PopulateListView()
{
	ListViewItem listViewItem=null;
	string [] files = Directory.GetFiles("C:\\temp");

	for (int i=0;i<files.Length;i++)
	{
		if (i%2==0)
			listViewItem = new ListViewItem(new string[] {files[i]}, -1, Color.Empty, Color.Red, new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(0))));
		else
			listViewItem = new ListViewItem(new string[] {files[i]}, -1, Color.Empty, Color.FromArgb(((System.Byte)(192)), ((System.Byte)(128)), ((System.Byte)(156))), null);
		this.listView1.Items.Add(listViewItem);
	}
}
private void button2_Click(object sender, System.EventArgs e)
{
	 FormatListView();
	PopulateListView();
}
obislavu
 
Thank you, but actually, just found out that the view property needed to be List. So my code was good.

Thanks anyway! :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top