listview.ItemsSource = observableCollection ques

M

mp

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(){}}
 
P

Peter Duniho

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
 
M

mp

Peter Duniho said:
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
 
P

Peter Duniho

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
 
M

mp

Peter Duniho said:
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
 
P

Peter Duniho

Peter Duniho said:
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 ...

Yes. As easy as it is to conflate them, it's important to keep in mind
the separation between C# the language, and .NET the framework. Strictly
speaking, C# doesn't require .NET, though it does require _some_ kind of
managed framework like .NET. And of course, the .NET framework can be
used from a wide variety of languages (C#, VB.NET, C++, F#, maybe some
others I'm forgetting at the moment, like Python, Ruby, etc.).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top