473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Fill listview with references

Hey,

I'm searching for a methode to get the the reference to an object I
added into a listview.

I got this class Address
class Address
{
private string street;
private string numb;
private string city;
private string country;
private string phone;
private string gsm;
private string email;
private string fax;

// and so on.....
// all got a property to acces
public Address(string street, string numb, string city, string
country, string phone, string gsm, string email, string fax)
{
this.street = street;
this.numb = numb;
this.city = city;
this.country = country;
this.phone = phone;
this.gsm = gsm;
this.email = email;
this.fax = fax;
}

public ArrayList ToItemList()
{
return new ListViewItem(new string[] { this.Naam, this.Voornaam,
this.Email }, -1);
}
}

In my mainform i got a listview where the street, numb and city are

ArrayList addressList = new ArrayList();
addressList.Add(new Address("street0", "numb0", "city0", "country0",
"phone0", "gsm0", "email0", "fax0"));
addressList.Add(new Address("street1", "numb1", "city1", "country1",
"phone1", "gsm1", "email1", "fax1"));
addressList.Add(new Address("street2", "numb2", "city2", "country2",
"phone2", "gsm2", "email2", "fax2"));
addressList.Add(new Address("street3", "numb3", "city3", "country3",
"phone3", "gsm3", "email3", "fax3"));

listView.Items.Clear();
foreach (Address address in addressList)
{
listView.Items.Add(address.ToItemList());
}

In the listview is now shown
street0 numb0 city0
street1 numb1 city1
street2 numb2 city2
street3 numb3 city3

The problem is now i can't get the other datamebers of a selected
item.
When an items is selected some textfields should get the value of
street, numb, city, country, phone, gsm, email and fax.

Thanks in advanced

Feb 7 '07 #1
3 1520
when you convert the to arrayList's you lose all that other information.
I believe that you will have to perform a lookup to reconnect that list item
to the address item.
Feb 8 '07 #2
On 8 feb, 03:35, XOR <X...@discussions.microsoft.comwrote:
when you convert the to arrayList's you lose all that other information.
I believe that you will have to perform a lookup to reconnect that list item
to the address item.
And how do i perform such a lookup?

Feb 8 '07 #3
in your postback you would have to load your datasource

ArrayList addressList = new ArrayList();
addressList.Add(new Address("street0", "numb0", "city0", "country0",
"phone0", "gsm0", "email0", "fax0"));
addressList.Add(new Address("street1", "numb1", "city1", "country1",
"phone1", "gsm1", "email1", "fax1"));
addressList.Add(new Address("street2", "numb2", "city2", "country2",
"phone2", "gsm2", "email2", "fax2"));
addressList.Add(new Address("street3", "numb3", "city3", "country3",
"phone3", "gsm3", "email3", "fax3"));

and then find the one that correlates the the selected item

ListViewItem selectedItem = listView.selectedItem;

Address selectedAddress = null;
foreach(Address a in addressList)
{
if ((a.street == selectedItem[0] ) &&
(a.number == selectedItem[1]) &&
(a.city == selectedItem[2])
{
//then we found it
selectedAddress = a;
break;
}
}
}

now u know which address the selected list item correlates to, so u can get
the other data.

this looping method isnt overly efficient though..
Feb 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: andrewcw | last post by:
I have a simple winform with the following code. But although I can read back the info, the display fails to provide the text or the cell background color changes. private void ListViewBroke()...
2
by: Sagaert Johan | last post by:
Hi I have set the columreorder to true Is there a way to get/set the current columnorder, so i can restore the order from a saved setting ? Johan
9
by: Devron Blatchford | last post by:
Hi there, Just wondering if I change the back and fore colour of a listview item when the mouse hovers over it? I want to overide the default windows colour. Can someone please tell me how to...
3
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate...
2
by: Matt Michael | last post by:
Hi, I'm having a problem working with a listview in an application I'm writing. Currently, whenever the selectedindex changed event fires, it loads up a htmledit control, and other labels on the...
2
by: mrmagoo | last post by:
I'm trying to fill a listview with data. I'm using the example from the help file, but how do I modify this to avoid using images? I want the exact same layout but without images. This procedure...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
2
by: Adrien Reboisson | last post by:
I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I installed SQL Server 2005 Express, created a blank project, dropped a TreeView, a ListView and a DataGridView : DB objects...
1
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, I would like to know how to optimally fill a ListView, which is defined as list, containing several columns? The ListView contains several columns with a certain column name: foreach...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.