Right. I didn't realize that you have to indicate the fields you used
as properties to the StringHolder class and assign
these properties to the dataGridView 's "DataPropertyName"  property.
Got my code fixed over the weekend. It works
now. Thanks again!


Benj


On Aug 24, 5:25 pm, Cerebrus <[EMAIL PROTECTED]> wrote:
> I don't see any Name, Age or Address properties in the StringHolder
> class.
>
> On Aug 23, 6:13 pm, Benj Nunez <[EMAIL PROTECTED]> wrote:
>
> > Hello experts,
>
> > I've been trying to resolve my problem with my code. I need to
> > retrieve the contents of a List<T>
> > and display it in a datagridview but I couldn't. I've tried this code
> > taken from some other sites/forums but it
> > wouldn't work for me. Here's my code:
>
> >         public void displayData()
> >         {
> >             PersonService service = new PersonService();
> >             dataGridView.DataSource = null;
>
> >             dataGridView.Columns.Add("Name", "Name");
> >             dataGridView.Columns[0].DataPropertyName = "Name";
> >             dataGridView.Columns.Add("Age", "Age");
> >             dataGridView.Columns[1].DataPropertyName = "Age";
> >             dataGridView.Columns.Add("Address", "Address");
> >             dataGridView.Columns[2].DataPropertyName = "Address";
>
> >             BindingSource personsBindingSource = new BindingSource();
> >             personsBindingSource.DataSource = service.showRecords();
> >             dataGridView.DataSource = personsBindingSource;  // no
> > strings in datagridview, just captions stated above.
> >         }
>
> > I've put the line 'dataGridView.AutoGenerateColumns = false;' under
> > the form's Load() event. The
> > service.showRecords() returns a List<StringHolder>.
>
> > The StringHolder which converts objects into strings is implemented
> > like this:
>
> >     class StringHolder
> >     {
> >         public string Value
> >         {
> >             get;
> >             set;
> >         }
>
> >         public StringHolder(string value)
> >         {
> >             this.Value = value;
> >         }
> >     }
>
> > Can someone help me on this one? Thanks in advance.
>
> > Benj

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to