473,395 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Putting list of objects into a datagridview

I have an object class "Person" say, with various public properties
including say "Name" and "Salary"

I have several person objects that I have created by some method outside the
scope of this discussion.

I want to setup a datagridview with each row corresponding to one person
object, and two columns being "Name" and "Salary". I want the user to be
able to click on the column heading to sort rows based on values in that
column. Users are not permitted to add to change rows, though can select
rows as operands to other operations.
This feels like it should be straightforward by setting up a collection of
persons as a datasource property either of the dataviewcontrol itself, or of
a bindingsource (which is then itself attached to the datagridview). However
whenever I go this route I seem to lose the (user) ability to sort on column
values.

Or, I can just add rows of {person.name, person.salary} pairs directly to
the datagridview but this is not very satisfactory as when the user selects
I want to get back the person object, not just the name and salary values.

What am I missing?

Sep 7 '06 #1
2 1575
"Tolgan" <to****@NOTTHISntlworld.coma écrit dans le message de news:
11****************@iris.uk.clara.net...

| What am I missing?

Create an instance of the BindingList<Tclass, passing your list to the
constructor, then set the DataGridView to that as DataSource. You may also
need to write a Comparer<Tderived class to implement IComparer<Tto
achieve sorting.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Sep 7 '06 #2
Gosh - a bit more programming than I expected to have to do given how nearly
the datagridview does it on its own without any datasource! But I've tried
your suggestion, certainly works and haven't come up with anything better,
so many thanks!

Chris (tolgan)

"Joanna Carter [TeamB]" <jo****@not.for.spamwrote in message
news:OJ**************@TK2MSFTNGP05.phx.gbl...
"Tolgan" <to****@NOTTHISntlworld.coma écrit dans le message de news:
11****************@iris.uk.clara.net...

| What am I missing?

Create an instance of the BindingList<Tclass, passing your list to the
constructor, then set the DataGridView to that as DataSource. You may also
need to write a Comparer<Tderived class to implement IComparer<Tto
achieve sorting.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


Sep 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
4
by: LMacd | last post by:
I thought binding a list of objects using would be a simple as assigning the list to the data source property of the datagridview object on my C# form through Visual Studio 2005. After reading many...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
3
by: admlangford | last post by:
Hi, I have a collection of objects which I am storing in a list the object looks like this struct Person { public int age; public string name; }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.