Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column in ListView

Tags:

c#

winforms

My application contains ListView with files that i am handling and have 3 columns: file name, length and status. Inside my for loop i am handling file after file and want in this case to change the status column from wait which is the value at the beginning to in process. is it possible to change one column ?

lvFiles is my ListView

for (int i = 0; i < lvFiles.Items.Count; i++)
{
    //here i am do things with my file
}

Here i am adding files into my ListView:

ListViewItem item = new ListViewItem(new string[] { new FileInfo(filePath).Name, duration, "Waiting" });
like image 340
user1269592 Avatar asked Jan 10 '13 22:01

user1269592


2 Answers

Use SubItems property of ListViewItem:

foreach(ListViewItem item in lvFiles.Items)
    item.SubItems[2].Text = "Waiting";
like image 172
Sergey Berezovskiy Avatar answered Nov 05 '22 07:11

Sergey Berezovskiy


You can try something like this if you know the specific Column for example Address would be colString[2] you can do a single line

string[] colString = new string{ "Starting", "Paused", "Waiting" };
int colIndex = 0;
foreach (ColumnHeader lstViewCol in lvFiles.Columns)
{
  lstViewCol.Text = colString[colIndex];
  colIndex++;
}

for single column you stated you wanted the 3rd column then you could something like this

lvFiles.Colunns[2] = "waiting"; 
like image 2
MethodMan Avatar answered Nov 05 '22 07:11

MethodMan