From: mp on
Hi
trying to populate a list view with data from objects contained in
collection
I'm getting the class name showing up in the listview not the values of each
property as i expected
what am i missing?

foreach loop populates collection
{...
myFuncs.Add(new FunctionInfo(FuncName, Signature, Foundin));


}

after for loop is done i try to fill listview with 3 columns with data from
3 properties of each obj in collection

lv1.Listview1.ItemsSource = myFuncs;

listview is filled but all entries in all collumns is classname
"WpfApplication1.FunctionInfo"

how do i get the values of the properties instead?

....the objects are defined thusly

myFuncs and FunctionInfo defined in FuntionList.cs

public class FunctionInfo

{

private String _Name;

private string _Signature;

private string _FileName;


public FunctionInfo(String name, string signature, string filename)

{this.Name = name;

this.Signature = signature;

this.FileName = filename;

}

public string Name

{

get { return _Name; }set { _Name = value; }}

public string Signature{get { return _Signature ; }set { _Signature =
value; }}

public string FileName{get { return _FileName; }set { _FileName = value; }}}

public class FunctionList :
System.Collections.ObjectModel.ObservableCollection<FunctionInfo>

{public FunctionList(): base(){}}





From: Peter Duniho on
On Sat, 03 Oct 2009 06:50:06 -0700, mp <nospam(a)thanks.com> wrote:

> Hi
> trying to populate a list view with data from objects contained in
> collection
> I'm getting the class name showing up in the listview not the values of
> each
> property as i expected
> what am i missing?

The display is done using the ToString() method of each object.
Apparently, you haven't overridden that method to provide the specific
output you want. The default implementation simply returns a string
containing the name of the type of the object.

Depending on your specific needs, you may either want to override
ToString() in the object itself, or provide a wrapper object with the
necessary ToString() override that's used for the sole purpose of being
used in the ListView.

Pete
From: mp on

"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:op.u1b7jhkrvmc1hu(a)macbook-pro.local...
> On Sat, 03 Oct 2009 06:50:06 -0700, mp <nospam(a)thanks.com> wrote:
>
>> Hi
>> trying to populate a list view with data from objects contained in
>> collection
>> I'm getting the class name showing up in the listview not the values of
>> each
>> property as i expected
>> what am i missing?
>
> The display is done using the ToString() method of each object.
> Apparently, you haven't overridden that method to provide the specific
> output you want. The default implementation simply returns a string
> containing the name of the type of the object.
>
> Depending on your specific needs, you may either want to override
> ToString() in the object itself, or provide a wrapper object with the
> necessary ToString() override that's used for the sole purpose of being
> used in the ListView.
>
> Pete

hmm I thought I'd deleted that post rather than sending...I finally
discovered I hadn't coded the xaml correctly to get the binding working...I
finally got that working..even if i barely understand how :-)
being new to c# i'm just reading and modifying numerous examples and
articles and guessing till it works <g>
I didn't override a .ToString method and will have to research exactly what
you're referring to there...
in my case i did the binding in xaml....maybe you're talking about a
codebehind method?
what i did was created a class to hold the 3 properties i wanted to display
created a resource out of that class
<Window.Resources>

<ObjectDataProvider x:Key="FunctionListDataSource"

ObjectType="{x:Type ds:FunctionList}"/>

</Window.Resources>

set the Binding source to the listview
<ListView ItemsSource="{Binding Source=

{StaticResource FunctionListDataSource}}"


and then what i was missing originally was setting each gridview column
DisplayMemberBinding
<GridViewColumn DisplayMemberBinding=

"{Binding Path=Name}"

once i got that in it worked as expected.

Thanks for the response, I'll look for that .ToString method of displaying
to compare

Thanks

mark


From: Peter Duniho on
On Mon, 05 Oct 2009 17:57:45 -0700, mp <nospam(a)thanks.com> wrote:

> hmm I thought I'd deleted that post rather than sending...I finally
> discovered I hadn't coded the xaml correctly to get the binding
> working...I
> finally got that working..even if i barely understand how :-)
> being new to c# i'm just reading and modifying numerous examples and
> articles and guessing till it works <g>
> I didn't override a .ToString method and will have to research exactly
> what
> you're referring to there...
> in my case i did the binding in xaml....maybe you're talking about a
> codebehind method? [...]

By default, I am always talking about C# code. This is, after all, a C#
newsgroup. :)

I understand from your post that you are coding in the WPF environment, in
which there are non-C# ways to modify presentation of your data. So in
this case, it seems that overriding ToString() is not necessary after
all. I would say that using the WPF-specific technique is probably
superior to overriding ToString(). I generally prefer data-driven
techniques over code modifications, when appropriate.

Pete
From: mp on

"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:op.u1ctdc18vmc1hu(a)macbook-pro.local...
> On Mon, 05 Oct 2009 17:57:45 -0700, mp <nospam(a)thanks.com> wrote:
>
>> in my case i did the binding in xaml....maybe you're talking about a
>> codebehind method? [...]
>
> By default, I am always talking about C# code. This is, after all, a C#
> newsgroup. :)

thanks for the clarificaton...since i'm using c# and wpf is one option in
that ide I was thinking it was part of c# but i'm starting to get that there
are technology overlaps in this world... dot net / c# / xaml / wpf ...

thanks for your patience
mark