Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Listview adding items to Dfferent columns

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sat Dec 26, 2009 3:51 pm    Post subject: [C#] Listview adding items to Dfferent columns Reply with quote

Im making a price tool, and I want it to have a listview, and when I press "Send", textbox1.text will appear in the 5th column. How would I do that?

Ive tried:

Code:
ListViewItem item = new ListViewItem();
            item.Text = textBox1.Text;
            listView1.Items.Add(item);


but all it does is send the string vertically down the first column.

Help Very Happy

_________________
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sun Dec 27, 2009 9:09 am    Post subject: Reply with quote

Change
Code:
listView1.Items.Add(item);
to
Code:
listView5.Items.Add(textbox1.Text);
, and remove the superfluous ListViewItem declaration.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sun Dec 27, 2009 4:13 pm    Post subject: Reply with quote

I dont have a control called listview5
_________________
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Mon Dec 28, 2009 10:47 am    Post subject: Reply with quote

Sneak wrote:
I dont have a control called listview5
Ah, my mistake. I misread it as ListBox. I haven't used this control before, but from what I read, you will have to do something like this:
Code:

public void PlaceAtIndex(int index, ListViewItem item, ListViewItem.ListViewSubItem subItem)
        {
            if(index > item.SubItems.Count-1)
            {
                for (int i = item.SubItems.Count; i < index; i++)
                {
                    item.SubItems.Add("");
                }
            item.SubItems.Add(subItem);
            }
            else
            {
                item.SubItems.RemoveAt(index);
                item.SubItems.Insert(index, subItem);
            }
        }


And then add it like this:
Code:
ListViewItem item = new ListViewItem();
            ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item,textbox1.Text);
            PlaceAtIndex(4, item, subItem);
            listView1.Items.Add(item);
There is probably an easier way, I just didn't find it.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Mon Dec 28, 2009 7:19 pm    Post subject: Reply with quote

Code:

private void ModifyItemString(ListViewSubItemCollection item, int index, string text)
{
     if (index < 0 || index > (item.Count - 1))
          throw new IndexOutOfRangeException();

     item[index].Text = text;
}


private void Send_Click(object sender, EventArgs e)
{
     ModifyItemString(listview.Items[<row you want to modify>].SubItems, 4, textbox.Text);
}


There are different ways to do it, but this is probably one of the easiest.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites