467,223 Members | 1,377 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,223 developers. It's quick & easy.

Tag property of List View Item

Jax
I understand that it's supposed to contain text, usually.
But as it takes an object can you be really cheeky and put
a very complex object in there instead?
Would any problems come from doing that?

jax
Nov 15 '05 #1
  • viewed: 4712
Share:
7 Replies
Hi Jax,

No problems whatsoever.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

"Jax" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
I understand that it's supposed to contain text, usually.
But as it takes an object can you be really cheeky and put
a very complex object in there instead?
Would any problems come from doing that?

jax

Nov 15 '05 #2
hmmm I dunno, it's giving me grief.
Seems to turning it into a value rather then a reference
or something.
I change other references to the same object but it stays
the same???
-----Original Message-----
Hi Jax,

No problems whatsoever.

--
Miha Markic - RightHand .NET consulting & software developmentmiha at rthand com

"Jax" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
I understand that it's supposed to contain text, usually. But as it takes an object can you be really cheeky and put a very complex object in there instead?
Would any problems come from doing that?

jax

.

Nov 15 '05 #3
Hi,

Tag is an object reference thus it stores the reference and does more
nothing to it.
What exactly is your problem?
Can you give us an example?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

<an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
hmmm I dunno, it's giving me grief.
Seems to turning it into a value rather then a reference
or something.
I change other references to the same object but it stays
the same???
-----Original Message-----
Hi Jax,

No problems whatsoever.

--
Miha Markic - RightHand .NET consulting & software

development
miha at rthand com

"Jax" <an*******@discussions.microsoft.com> wrote in

message
news:04****************************@phx.gbl...
I understand that it's supposed to contain text, usually. But as it takes an object can you be really cheeky and put a very complex object in there instead?
Would any problems come from doing that?

jax

.

Nov 15 '05 #4
Jax
Thanks for your attention Miha,

Okay i'll try to keep it brief:

Imagine a form with a listview on the left.
In the background of the form there is an objerct called
theCase of custom type Case.
This contains an arraylist of references to all customer
objects.
The list view on the left represent all the customers, if
you click add customer this happens.

private void btnAddApplicant_Click(object sender,
System.EventArgs e)
{
ready = true;
ctr++;
Customer c = new Customer();
c.PersonalDetails.FirstName = "Name";
c.PersonalDetails.SecondName = "Me" + ctr.ToString();
theCase.Customers.Add(c);
ListViewItem lvi = new ListViewIte
(c.PersonalDetails.FirstName + " " +
c.PersonalDetails.SecondName, 0);
lvi.Tag = (object)c;
lvi.Selected = true;
this.lstCustomers.Items.Add(lvi);
}
So I put the reference into theCase as well as the Tag of
the listview.

If the selected index of the listview changes this happens.

if(this.lstCustomers.SelectedItems != null)
{
if(this.lstCustomers.SelectedItems.Count>0)
{
if(ready)
{
this.txtPersonalC1FirstName.Focus();
SaveCustomer();
theCustomer = (Customer) lstCustomers.SelectedItems[0].Tag;
this.PopulateFromCustomer(theCustomer);
foreach(ListViewItem listItems in lstCustomers.Items)
{
listItems.ImageIndex = 0;
}
lstCustomers.SelectedItems[0].ImageIndex = 1;
if(theCase.Customers.Count<2)
{
this.btnCopyAddresses.Visible = false;
this.btnCopyDependants.Visible = false;
}
else
{
this.btnCopyAddresses.Visible = true;
this.btnCopyDependants.Visible = true;
}
CreateSelfCertTable();
RefreshCopyCombos();
}
CreateSelfCertTable();
RefreshCopyCombos();
}
}
}

Save Customer does this.

private void SaveCustomer()
{
foreach(ListViewItem lvi in this.lstCustomers.Items)
{
if(lvi.ImageIndex == 1)
{
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
break;
}
}
}

Do you remember at the top when I created the objects I
put a refrence in theCase custom type of Case.
Thing is is that I pass this object to my copyCommand form
and it has customers with their inital names ("Name Me1")
rather then the names i've put on since then.

With the load and the save method i have twined in with
the selected item changed event I can see that I am making
changes and these are being registered with the Customer
object as they are loading out all the details corrctly.

Any idea why theCase has outofdate references?
If you've got this far I thank you for your patience. :)
jax
-----Original Message-----
Hi,

Tag is an object reference thus it stores the reference and does morenothing to it.
What exactly is your problem?
Can you give us an example?

--
Miha Markic - RightHand .NET consulting & software developmentmiha at rthand com

<an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
hmmm I dunno, it's giving me grief.
Seems to turning it into a value rather then a reference
or something.
I change other references to the same object but it stays the same???
>-----Original Message-----
>Hi Jax,
>
>No problems whatsoever.
>
>--
>Miha Markic - RightHand .NET consulting & software

development
>miha at rthand com
>
>"Jax" <an*******@discussions.microsoft.com> wrote in

message
>news:04****************************@phx.gbl...
>> I understand that it's supposed to contain text,

usually.
>> But as it takes an object can you be really cheeky
and put
>> a very complex object in there instead?
>> Would any problems come from doing that?
>>
>> jax
>
>
>.
>

.

Nov 15 '05 #5
HI Jax,

I could be wrong, though (near the end):
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
You are assigning new customer to tag while theCase still has old reference
(to old customer).
Is this what you are missing?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

"Jax" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl... Thanks for your attention Miha,

Okay i'll try to keep it brief:

Imagine a form with a listview on the left.
In the background of the form there is an objerct called
theCase of custom type Case.
This contains an arraylist of references to all customer
objects.
The list view on the left represent all the customers, if
you click add customer this happens.

private void btnAddApplicant_Click(object sender,
System.EventArgs e)
{
ready = true;
ctr++;
Customer c = new Customer();
c.PersonalDetails.FirstName = "Name";
c.PersonalDetails.SecondName = "Me" + ctr.ToString();
theCase.Customers.Add(c);
ListViewItem lvi = new ListViewIte
(c.PersonalDetails.FirstName + " " +
c.PersonalDetails.SecondName, 0);
lvi.Tag = (object)c;
lvi.Selected = true;
this.lstCustomers.Items.Add(lvi);
}
So I put the reference into theCase as well as the Tag of
the listview.

If the selected index of the listview changes this happens.

if(this.lstCustomers.SelectedItems != null)
{
if(this.lstCustomers.SelectedItems.Count>0)
{
if(ready)
{
this.txtPersonalC1FirstName.Focus();
SaveCustomer();
theCustomer = (Customer) lstCustomers.SelectedItems[0].Tag;
this.PopulateFromCustomer(theCustomer);
foreach(ListViewItem listItems in lstCustomers.Items)
{
listItems.ImageIndex = 0;
}
lstCustomers.SelectedItems[0].ImageIndex = 1;
if(theCase.Customers.Count<2)
{
this.btnCopyAddresses.Visible = false;
this.btnCopyDependants.Visible = false;
}
else
{
this.btnCopyAddresses.Visible = true;
this.btnCopyDependants.Visible = true;
}
CreateSelfCertTable();
RefreshCopyCombos();
}
CreateSelfCertTable();
RefreshCopyCombos();
}
}
}

Save Customer does this.

private void SaveCustomer()
{
foreach(ListViewItem lvi in this.lstCustomers.Items)
{
if(lvi.ImageIndex == 1)
{
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
break;
}
}
}

Nov 15 '05 #6
Jax
Miha,

You are right, you are awesome!
Thankyou soooooo much that's sorted EVERYTHING!
You the man!

a very happy jax.
-----Original Message-----
HI Jax,

I could be wrong, though (near the end):
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
You are assigning new customer to tag while theCase still

has old reference(to old customer).
Is this what you are missing?

--
Miha Markic - RightHand .NET consulting & software developmentmiha at rthand com

"Jax" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
Thanks for your attention Miha,

Okay i'll try to keep it brief:

Imagine a form with a listview on the left.
In the background of the form there is an objerct called
theCase of custom type Case.
This contains an arraylist of references to all customer
objects.
The list view on the left represent all the customers, if you click add customer this happens.

private void btnAddApplicant_Click(object sender,
System.EventArgs e)
{
ready = true;
ctr++;
Customer c = new Customer();
c.PersonalDetails.FirstName = "Name";
c.PersonalDetails.SecondName = "Me" + ctr.ToString();
theCase.Customers.Add(c);
ListViewItem lvi = new ListViewIte
(c.PersonalDetails.FirstName + " " +
c.PersonalDetails.SecondName, 0);
lvi.Tag = (object)c;
lvi.Selected = true;
this.lstCustomers.Items.Add(lvi);
}
So I put the reference into theCase as well as the Tag of the listview.

If the selected index of the listview changes this happens.
if(this.lstCustomers.SelectedItems != null)
{
if(this.lstCustomers.SelectedItems.Count>0)
{
if(ready)
{
this.txtPersonalC1FirstName.Focus();
SaveCustomer();
theCustomer = (Customer) lstCustomers.SelectedItems [0].Tag; this.PopulateFromCustomer(theCustomer);
foreach(ListViewItem listItems in lstCustomers.Items)
{
listItems.ImageIndex = 0;
}
lstCustomers.SelectedItems[0].ImageIndex = 1;
if(theCase.Customers.Count<2)
{
this.btnCopyAddresses.Visible = false;
this.btnCopyDependants.Visible = false;
}
else
{
this.btnCopyAddresses.Visible = true;
this.btnCopyDependants.Visible = true;
}
CreateSelfCertTable();
RefreshCopyCombos();
}
CreateSelfCertTable();
RefreshCopyCombos();
}
}
}

Save Customer does this.

private void SaveCustomer()
{
foreach(ListViewItem lvi in this.lstCustomers.Items)
{
if(lvi.ImageIndex == 1)
{
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
break;
}
}
}

.

Nov 15 '05 #7
Jax,

1st) you do not need to cast to an (Object) when you assign a tag.
Everything is an object.

2nd) I've had discrepencies with putting objects on to tags before. The
best way I've found is to assign the tag everytime the object changes.

Hope this helps

Marco

"Jax" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Thanks for your attention Miha,

Okay i'll try to keep it brief:

Imagine a form with a listview on the left.
In the background of the form there is an objerct called
theCase of custom type Case.
This contains an arraylist of references to all customer
objects.
The list view on the left represent all the customers, if
you click add customer this happens.

private void btnAddApplicant_Click(object sender,
System.EventArgs e)
{
ready = true;
ctr++;
Customer c = new Customer();
c.PersonalDetails.FirstName = "Name";
c.PersonalDetails.SecondName = "Me" + ctr.ToString();
theCase.Customers.Add(c);
ListViewItem lvi = new ListViewIte
(c.PersonalDetails.FirstName + " " +
c.PersonalDetails.SecondName, 0);
lvi.Tag = (object)c;
lvi.Selected = true;
this.lstCustomers.Items.Add(lvi);
}
So I put the reference into theCase as well as the Tag of
the listview.

If the selected index of the listview changes this happens.

if(this.lstCustomers.SelectedItems != null)
{
if(this.lstCustomers.SelectedItems.Count>0)
{
if(ready)
{
this.txtPersonalC1FirstName.Focus();
SaveCustomer();
theCustomer = (Customer) lstCustomers.SelectedItems[0].Tag;
this.PopulateFromCustomer(theCustomer);
foreach(ListViewItem listItems in lstCustomers.Items)
{
listItems.ImageIndex = 0;
}
lstCustomers.SelectedItems[0].ImageIndex = 1;
if(theCase.Customers.Count<2)
{
this.btnCopyAddresses.Visible = false;
this.btnCopyDependants.Visible = false;
}
else
{
this.btnCopyAddresses.Visible = true;
this.btnCopyDependants.Visible = true;
}
CreateSelfCertTable();
RefreshCopyCombos();
}
CreateSelfCertTable();
RefreshCopyCombos();
}
}
}

Save Customer does this.

private void SaveCustomer()
{
foreach(ListViewItem lvi in this.lstCustomers.Items)
{
if(lvi.ImageIndex == 1)
{
theCustomer = this.SaveCustomerFromForm();
lvi.Text = theCustomer.PersonalDetails.FirstName + " " +
theCustomer.PersonalDetails.SecondName;
lvi.Tag = (object)theCustomer;
break;
}
}
}

Do you remember at the top when I created the objects I
put a refrence in theCase custom type of Case.
Thing is is that I pass this object to my copyCommand form
and it has customers with their inital names ("Name Me1")
rather then the names i've put on since then.

With the load and the save method i have twined in with
the selected item changed event I can see that I am making
changes and these are being registered with the Customer
object as they are loading out all the details corrctly.

Any idea why theCase has outofdate references?
If you've got this far I thank you for your patience. :)
jax
-----Original Message-----
Hi,

Tag is an object reference thus it stores the reference

and does more
nothing to it.
What exactly is your problem?
Can you give us an example?

--
Miha Markic - RightHand .NET consulting & software

development
miha at rthand com

<an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
hmmm I dunno, it's giving me grief.
Seems to turning it into a value rather then a reference
or something.
I change other references to the same object but it stays the same???
>-----Original Message-----
>Hi Jax,
>
>No problems whatsoever.
>
>--
>Miha Markic - RightHand .NET consulting & software
development
>miha at rthand com
>
>"Jax" <an*******@discussions.microsoft.com> wrote in
message
>news:04****************************@phx.gbl...
>> I understand that it's supposed to contain text,
usually.
>> But as it takes an object can you be really cheeky and put
>> a very complex object in there instead?
>> Would any problems come from doing that?
>>
>> jax
>
>
>.
>

.

Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Anushya | last post: by
2 posts views Thread by louise raisbeck | last post: by
6 posts views Thread by Altman | last post: by
5 posts views Thread by Kimmo Laine | last post: by
8 posts views Thread by Papa.Coen | last post: by
1 post views Thread by shapper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.