user1269592
user1269592

Reputation: 701

Change column in ListView

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" });

Upvotes: 6

Views: 5143

Answers (2)

MethodMan
MethodMan

Reputation: 18863

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"; 

Upvotes: 2

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236308

Use SubItems property of ListViewItem:

foreach(ListViewItem item in lvFiles.Items)
    item.SubItems[2].Text = "Waiting";

Upvotes: 4

Related Questions