-
April 5th, 2014, 12:08 PM
#1
Place text in a specific listview item columnheader?
The following code produces the following picture with 1 problem; the timestamp/values do not actually update (they stay at the same time / values after the '=' stay at 0); however, I need them to update (as they do when viewed in debugView).
Code:
private void AppendText(int i, int pid, string text)
{
// Trim ending newline (if any)
if (text.EndsWith(Environment.NewLine))
text = text.Substring(0, text.Length - Environment.NewLine.Length);
ListViewItem item = null;
// Replace every '\r\n' with '\n' so we can easily split into
// all lines
text = text.Replace("\r\n", "\n");
foreach (string line in text.Split('\n'))
{
if (item != null)
{
item = listView1.Items.Add("");
item.SubItems.Add("");
item.SubItems.Add("");
item.SubItems.Add("");
}
else
{
item = listView1.Items.Add("");
item.SubItems.Add(DateTime.Now.ToString("HH:mm:ss"));
item.SubItems.Add(pid.ToString());
item.SubItems.Add(GetProcessName(pid));
}
item.SubItems.Add(line);
}
item.EnsureVisible();
}
I tried to edit the aforementioned code to produce what I am trying to achieve, sadly the following did not work (nothing was displayed);
Code:
private void AppendText(int i, int pid, string text)
{
// Trim ending newline (if any)
if (text.EndsWith(Environment.NewLine))
text = text.Substring(0, text.Length - Environment.NewLine.Length);
// Replace every '\r\n' with '\n' so we can easily split into
// all lines
text = text.Replace("\r\n", "\n");
foreach (string line in text.Split('\n'))
{
listView1.Items[i].SubItems[1].Text = DateTime.Now.ToString("HH:mm:ss");
listView1.Items[i].SubItems[2].Text = pid.ToString();
listView1.Items[i].SubItems[3].Text = GetProcessName(pid);
listView1.Items[i].SubItems[4].Text = line;
}
listView1.Items[i].EnsureVisible();
}
How can I accomplish my task?
- Please note that I made the column-headers in the UI editor of VS (did not make programmatically) and what you are seeing in the pictures is as follows; timestamp = columnheader2 pid = columnheader3 name = columnheader4 text = columnheader5
- Please note that in the second edited function, 'i' is an integer andevery time I call 'AppendText', 'i' is increased by 1 (i++) and that when it hits numerical value 6, it resets to 0.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|