Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Q: ValueObject design pattern and DataGrid control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guy Mahieu - 01 Oct 2004 21:44 GMT
Hello all,

I've been developing enterprise solutions in Java for a few years now, and I
became quite curious about .NET.  When the opportunity arose to start a new
(relatively small) project, I chose to give c# a try.

I am used to implementing a ValueObject pattern when it comes to retrieving
data from a datasource and showing it in a grid (table) or form view.  I was
curious about the best way to go about this in dotnet using the DataGrid
component, can it display custom objects as rows and how do you bind columns
to properties or fields of those row objects?  What are the do's and don'ts
when it comes to adding data to and editing data in a DataGrid component?

The application I am trying to put together is a single tier application
deployed on a few workstations that each connect to a (mysql) database on a
server.

Thanks in advance for your hints, comments, ...

Greetings,

Guy
Dave Foderick - 01 Oct 2004 22:13 GMT
Hi Guy,

.NET can databind to custom objects as long as they have public properties
(cannot bind to fields). The collection that holds your objects should
implement IBindingList or at least IList. Where you will run into problems
is binding to null value properties like DateTime. In that case you may have
to create a subclass of the Binding class and override the OnFormat and
OnParse methods. Also for sorting look at the IComparer interface. Hopefully
databinding to custom objects will get easier with .NET 2.0

-Dave Foderick

> Hello all,
>
[quoted text clipped - 18 lines]
>
> Guy
Guy Mahieu - 02 Oct 2004 12:00 GMT
Thanks, this seems to work just fine, there is one drawback though, now all
my properties are exposed to the grid and the columnheaders show the propety
names as they were set in the class.  What would be the best way to
customize the visible columns and their headers without altering the
underlying value object classes?

Greetings,

Guy

> Hi Guy,
>
[quoted text clipped - 37 lines]
> >
> > Guy
ClayB [Syncfusion] - 03 Oct 2004 10:23 GMT
To control the columns and their order in the DataGrid, you can add a
DataGridTableStyle to the DataGrid's TableStyles collection. In this
tablestyle, add columnstyles to the tablestyle1.GridColumnStyles for each
column you want to see. Here is a FAQ discussing this process for a
DataTable, but it will also work for other datasources.

    How can I programatically add and remove columns in my DataGrid without
modifying the DataTable datasource?
    http://www.syncfusion.com/faq/winforms/search/1070.asp

One point to note is the MappingName you assign to the tablestyle is
crucial. If it in not the proper value, the grid will not use the
tablestyle. Here is a FAQ that has a method that you can use to determine
the string you must use for the MappingName.

    How do I determine the DataGridTableStyle MappingName that should used
for a DataGrid to make sure the grid uses my tablestyle ?
    http://www.syncfusion.com/faq/winforms/search/931.asp

=============================================
Clay Burch, .NET MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials

> Thanks, this seems to work just fine, there is one drawback though, now
> all
[quoted text clipped - 59 lines]
>> >
>> > Guy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.