how to add details in specific column in list view
I wanna add details to watchers column like my following image.. I use following code to add those details.But it prints in 1st column.. could anybody tell me to do this.
screenshot
Here's the code I've used:
private void addwatchers(string watchers)
string row = watchers ;
ListViewItem item = new ListViewItem(row);
//ADD ITEMS
listView1.Items.Add(item);
private void button2_Click(object sender, System.EventArgs e)
string cwatchers = richTextBox2.Text.Split('n');
for (int i=0;i<cwatchers.Length;i++)
addwatchers(cwatchers[i]);
c# listview
add a comment |
I wanna add details to watchers column like my following image.. I use following code to add those details.But it prints in 1st column.. could anybody tell me to do this.
screenshot
Here's the code I've used:
private void addwatchers(string watchers)
string row = watchers ;
ListViewItem item = new ListViewItem(row);
//ADD ITEMS
listView1.Items.Add(item);
private void button2_Click(object sender, System.EventArgs e)
string cwatchers = richTextBox2.Text.Split('n');
for (int i=0;i<cwatchers.Length;i++)
addwatchers(cwatchers[i]);
c# listview
You're passing a single-item array to create theListViewItem
so it's only populating the first column. Create the row array first with all the column values and call theaddWatchers()
method once per line.
– Karel Tamayo
Nov 15 '18 at 19:04
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20
add a comment |
I wanna add details to watchers column like my following image.. I use following code to add those details.But it prints in 1st column.. could anybody tell me to do this.
screenshot
Here's the code I've used:
private void addwatchers(string watchers)
string row = watchers ;
ListViewItem item = new ListViewItem(row);
//ADD ITEMS
listView1.Items.Add(item);
private void button2_Click(object sender, System.EventArgs e)
string cwatchers = richTextBox2.Text.Split('n');
for (int i=0;i<cwatchers.Length;i++)
addwatchers(cwatchers[i]);
c# listview
I wanna add details to watchers column like my following image.. I use following code to add those details.But it prints in 1st column.. could anybody tell me to do this.
screenshot
Here's the code I've used:
private void addwatchers(string watchers)
string row = watchers ;
ListViewItem item = new ListViewItem(row);
//ADD ITEMS
listView1.Items.Add(item);
private void button2_Click(object sender, System.EventArgs e)
string cwatchers = richTextBox2.Text.Split('n');
for (int i=0;i<cwatchers.Length;i++)
addwatchers(cwatchers[i]);
c# listview
c# listview
edited Nov 15 '18 at 19:07
Karel Tamayo
2,77221522
2,77221522
asked Nov 15 '18 at 18:54
Ebay BoostingEbay Boosting
93
93
You're passing a single-item array to create theListViewItem
so it's only populating the first column. Create the row array first with all the column values and call theaddWatchers()
method once per line.
– Karel Tamayo
Nov 15 '18 at 19:04
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20
add a comment |
You're passing a single-item array to create theListViewItem
so it's only populating the first column. Create the row array first with all the column values and call theaddWatchers()
method once per line.
– Karel Tamayo
Nov 15 '18 at 19:04
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20
You're passing a single-item array to create the
ListViewItem
so it's only populating the first column. Create the row array first with all the column values and call the addWatchers()
method once per line.– Karel Tamayo
Nov 15 '18 at 19:04
You're passing a single-item array to create the
ListViewItem
so it's only populating the first column. Create the row array first with all the column values and call the addWatchers()
method once per line.– Karel Tamayo
Nov 15 '18 at 19:04
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20
add a comment |
1 Answer
1
active
oldest
votes
Every time you call addWatchers()
you create a list view item (a row in the list view). You have several ways of creating such items. The one you're currently using is passing an array of string, which represents the column values (by position) to create each item.
What I'd do is to create the ListViewItem
in the caller method instead:
for (int i = 0; i < cwatchers.Length; i++)
var item = new ListViewItem(i.ToString()); //<-- arbitrarily using i as the value for the first column. You should use whatever makes sense to you.
//TODO: add the sub item for the ID column
item.SubItems.Add("");
//Add in Watchers
item.SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
//Add the item to the list view
listView1.Items.Add(item);
You can safely get rid of the addwatchers
method since it's only adding the corresponding subitem.
UPDATE
If you already have the items created when you call addWatchers, then the only thing you need to do is iterate through the items in the list view and add the missing sub items.
Let's say you have added in a previous process all the items to the listview. And when you did that, you created the listview item with two columns.
private void button2_Click(object sender, EventArgs e)
string cwatchers = richTextBox2Text.Split('n');
for (int i = 0; i < cwatchers.Length; i++)
//Get the listview item in i and add the sub item for the watchers.
//this assumes that the list view item is created and contains two subitems so the next one to be added is the wawtchers.
listView1.Items[i].SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
Hope this helps!
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326167%2fhow-to-add-details-in-specific-column-in-list-view%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Every time you call addWatchers()
you create a list view item (a row in the list view). You have several ways of creating such items. The one you're currently using is passing an array of string, which represents the column values (by position) to create each item.
What I'd do is to create the ListViewItem
in the caller method instead:
for (int i = 0; i < cwatchers.Length; i++)
var item = new ListViewItem(i.ToString()); //<-- arbitrarily using i as the value for the first column. You should use whatever makes sense to you.
//TODO: add the sub item for the ID column
item.SubItems.Add("");
//Add in Watchers
item.SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
//Add the item to the list view
listView1.Items.Add(item);
You can safely get rid of the addwatchers
method since it's only adding the corresponding subitem.
UPDATE
If you already have the items created when you call addWatchers, then the only thing you need to do is iterate through the items in the list view and add the missing sub items.
Let's say you have added in a previous process all the items to the listview. And when you did that, you created the listview item with two columns.
private void button2_Click(object sender, EventArgs e)
string cwatchers = richTextBox2Text.Split('n');
for (int i = 0; i < cwatchers.Length; i++)
//Get the listview item in i and add the sub item for the watchers.
//this assumes that the list view item is created and contains two subitems so the next one to be added is the wawtchers.
listView1.Items[i].SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
Hope this helps!
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
|
show 7 more comments
Every time you call addWatchers()
you create a list view item (a row in the list view). You have several ways of creating such items. The one you're currently using is passing an array of string, which represents the column values (by position) to create each item.
What I'd do is to create the ListViewItem
in the caller method instead:
for (int i = 0; i < cwatchers.Length; i++)
var item = new ListViewItem(i.ToString()); //<-- arbitrarily using i as the value for the first column. You should use whatever makes sense to you.
//TODO: add the sub item for the ID column
item.SubItems.Add("");
//Add in Watchers
item.SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
//Add the item to the list view
listView1.Items.Add(item);
You can safely get rid of the addwatchers
method since it's only adding the corresponding subitem.
UPDATE
If you already have the items created when you call addWatchers, then the only thing you need to do is iterate through the items in the list view and add the missing sub items.
Let's say you have added in a previous process all the items to the listview. And when you did that, you created the listview item with two columns.
private void button2_Click(object sender, EventArgs e)
string cwatchers = richTextBox2Text.Split('n');
for (int i = 0; i < cwatchers.Length; i++)
//Get the listview item in i and add the sub item for the watchers.
//this assumes that the list view item is created and contains two subitems so the next one to be added is the wawtchers.
listView1.Items[i].SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
Hope this helps!
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
|
show 7 more comments
Every time you call addWatchers()
you create a list view item (a row in the list view). You have several ways of creating such items. The one you're currently using is passing an array of string, which represents the column values (by position) to create each item.
What I'd do is to create the ListViewItem
in the caller method instead:
for (int i = 0; i < cwatchers.Length; i++)
var item = new ListViewItem(i.ToString()); //<-- arbitrarily using i as the value for the first column. You should use whatever makes sense to you.
//TODO: add the sub item for the ID column
item.SubItems.Add("");
//Add in Watchers
item.SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
//Add the item to the list view
listView1.Items.Add(item);
You can safely get rid of the addwatchers
method since it's only adding the corresponding subitem.
UPDATE
If you already have the items created when you call addWatchers, then the only thing you need to do is iterate through the items in the list view and add the missing sub items.
Let's say you have added in a previous process all the items to the listview. And when you did that, you created the listview item with two columns.
private void button2_Click(object sender, EventArgs e)
string cwatchers = richTextBox2Text.Split('n');
for (int i = 0; i < cwatchers.Length; i++)
//Get the listview item in i and add the sub item for the watchers.
//this assumes that the list view item is created and contains two subitems so the next one to be added is the wawtchers.
listView1.Items[i].SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
Hope this helps!
Every time you call addWatchers()
you create a list view item (a row in the list view). You have several ways of creating such items. The one you're currently using is passing an array of string, which represents the column values (by position) to create each item.
What I'd do is to create the ListViewItem
in the caller method instead:
for (int i = 0; i < cwatchers.Length; i++)
var item = new ListViewItem(i.ToString()); //<-- arbitrarily using i as the value for the first column. You should use whatever makes sense to you.
//TODO: add the sub item for the ID column
item.SubItems.Add("");
//Add in Watchers
item.SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
//Add the item to the list view
listView1.Items.Add(item);
You can safely get rid of the addwatchers
method since it's only adding the corresponding subitem.
UPDATE
If you already have the items created when you call addWatchers, then the only thing you need to do is iterate through the items in the list view and add the missing sub items.
Let's say you have added in a previous process all the items to the listview. And when you did that, you created the listview item with two columns.
private void button2_Click(object sender, EventArgs e)
string cwatchers = richTextBox2Text.Split('n');
for (int i = 0; i < cwatchers.Length; i++)
//Get the listview item in i and add the sub item for the watchers.
//this assumes that the list view item is created and contains two subitems so the next one to be added is the wawtchers.
listView1.Items[i].SubItems.Add(cwatchers[i]);
//TODO: add the rest of the sub items
Hope this helps!
edited Nov 15 '18 at 21:02
answered Nov 15 '18 at 19:29
Karel TamayoKarel Tamayo
2,77221522
2,77221522
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
|
show 7 more comments
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
nope. this is not working...
– Ebay Boosting
Nov 15 '18 at 20:32
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
I don't need to type like this. prntscr.com/livh7n
– Ebay Boosting
Nov 15 '18 at 20:34
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
How are you adding the previous items? If those are already there you'll have this issue. Is the listview empty at the beginning?
– Karel Tamayo
Nov 15 '18 at 20:35
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
this is what i want.. prntscr.com/livlax
– Ebay Boosting
Nov 15 '18 at 20:43
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
Where are you taking the IDs from? Are you adding them in a different moment?
– Karel Tamayo
Nov 15 '18 at 20:48
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326167%2fhow-to-add-details-in-specific-column-in-list-view%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You're passing a single-item array to create the
ListViewItem
so it's only populating the first column. Create the row array first with all the column values and call theaddWatchers()
method once per line.– Karel Tamayo
Nov 15 '18 at 19:04
I did like that. but i cannot get the result that i want...
– Ebay Boosting
Nov 15 '18 at 19:20