From: Peter Duniho on
Jeff Johnson wrote:
> "Jackie" <Jackie(a)an.on> wrote in message
> news:4bf59be2$0$5849$c3e8da3(a)news.astraweb.com...
>
>>>> I think the sensible thing to do would be either
>>>> dict1["key1"] = new Struct1(Convert.ToInt32(xmlText));
>>> Does that work? For some reason I had it in my head that you couldn't
>>> simply
>>> assign like that. Maybe I'm confusing that with something else.
>
>> I gave it a try now to make sure and it worked.
>
> Good to know, thanks.

Just to be complete:

Calling Add() with a key that already exists will fail with an
exception. But using the indexer on the type won't, even if the key
already is present (the existing value is replaced with the new one).

Pete
From: Jeff Johnson on

"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:%23OA1oyI%23KHA.5164(a)TK2MSFTNGP02.phx.gbl...

>>>>> I think the sensible thing to do would be either
>>>>> dict1["key1"] = new Struct1(Convert.ToInt32(xmlText));
>>>> Does that work? For some reason I had it in my head that you couldn't
>>>> simply
>>>> assign like that. Maybe I'm confusing that with something else.
>>
>>> I gave it a try now to make sure and it worked.
>>
>> Good to know, thanks.
>
> Just to be complete:
>
> Calling Add() with a key that already exists will fail with an exception.
> But using the indexer on the type won't, even if the key already is
> present (the existing value is replaced with the new one).

Maybe I'm thinking of something in Windows Forms, like a tree view or a list
view where you can't simply change a node/list item by just replacing it;
you have to remove and re-add.


From: Jackie on
On 5/21/2010 07:40, Jeff Johnson wrote:
> Maybe I'm thinking of something in Windows Forms, like a tree view or a list
> view where you can't simply change a node/list item by just replacing it;
> you have to remove and re-add.
>

I gave this a try now:

treeView1.Nodes[0] = new TreeNode("Replaced node");
listView1.Items[0] = new ListViewItem("Replaced item");

TreeView: New node is inserted.
ListView: Existing item is replaced.

I wonder why it works like that.
From: Jeff Johnson on
"Jackie" <Jackie(a)an.on> wrote in message
news:4bf636fb$0$20981$c3e8da3(a)news.astraweb.com...

>> Maybe I'm thinking of something in Windows Forms, like a tree view or a
>> list
>> view where you can't simply change a node/list item by just replacing it;
>> you have to remove and re-add.
>>
>
> I gave this a try now:
>
> treeView1.Nodes[0] = new TreeNode("Replaced node");
> listView1.Items[0] = new ListViewItem("Replaced item");
>
> TreeView: New node is inserted.
> ListView: Existing item is replaced.
>
> I wonder why it works like that.

Okay, now I plead "flashback to VB6." It's the only explanation I have left.