DataGrids - I give up!

Posted on 2005-05-14
Last Modified: 2010-04-16
Still learning, so keep that in mind.

I've been reading about DataGrids because I need one in my application.  They make no sense to me.  At all.  None.  Microsoft took something that should be very simple and made it the most incoherent, convoluted thing ever.  And I thought the Swing equal to a DataGrid was bad. :)

Here's all I want to do:

A DataGrid with 3 columns, the last of those columns containing 3 controls (LinkLabels).  I'm generating the DataTable programatically (not from a database, from another source) cause that's the only way this even makes a bit of sense to me.  The columns are readonly, their widths are equal, and they should be sortable by clicking on the heading.  That's all I want to do.  Nearly the simplest thing possible.  My main issue with this whole thing is the designer won't let me bing my DataTable to the DataGrid and it has to be done programatically.  Isn't the point of DataGrids + the forms designer to completely avoid getting into the gory details?

Learning C# and Forms had been a pleasure up until then.  Now I'm just pulling my hair out.

Thanks much for any help regarding this.
Question by:dbunder
    LVL 10

    Expert Comment

    um ... So what is the problem? Its easy to bind the DataGrid to a DataTable, I don't think I caught what the problem is exactly. You can do this totally through the designer but its like two lines of code if you program it. Maybe I am missing somehting ...
    LVL 1

    Author Comment

    What I'm basically asking is how you do it through the designer.  I'm unable to bind anything that way, though I do know how to do it programmatically.  From reading Microsoft's docs, it's supposed to be the easiest thing in the world... I just can't figure out how to do it.  Can't attach styles to the columns through the designer either, which is another thing that's supposedly easy to do from within the designer.

    Also wanted to know how to add controls to datagrid cels.  Haven't been able to find much of anything about this.
    LVL 12

    Expert Comment

    Hey Dbunder -

      you right click on the data grid in designer to choose formatting options.

    LVL 1

    Author Comment

    Is this to apply styles to the datagrid?  All I was able to find was "Auto Formatting" which changes colors and whatnot based on templates.
    LVL 69

    Accepted Solution

    The DataGrid sucks. Microsoft never gave a full featured grid component (and no real numeric/masked textbox neither). It lets this parts to 3rd party components.

    Have a look at this site:
    LVL 96

    Expert Comment

    by:Bob Learned
    Micro$oft is just being true to form.  It has never had a good grid control in any version of any product:  C++, VB3/4/5/6, and now VB.NET and C#.

    LVL 7

    Expert Comment

    Alright... to do what you want through the designed here is what you need to do...

    1) Goto the properties for you data grid.
    2) Goto the TableStyles property and click in the box.  This will give an ?elips? button (...), which you click on to bring up a dialog.
    3) In the dialog you need to set the mapping name to the name of your DataTable.
    4) If you want to, you can modify the cloumns by going into the GridColumnStyles.
    5) Programatically, assign you data table to the data grid then display.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now