DataGridView not displaying all columns

Posted on 2009-02-12
Last Modified: 2013-12-17
I have a datagridview that is populated from a dataset.

The dataset came from a ReadXML command ... so I have something like the code below.

When I traverse the columns in dataset1.Tables["services"], I can see the column called "service_id", however this column does not exist in the datagridview.

In addition I have another table - dataset1.Tables["references"] - again this has two columns, service_id and member_id, again when I display this I do not see the columns.

And finally another table called "member" which has the column member_id.

I understand that these are generated by the ReadXML and maintain the integrity of the datatables and how they all link together, but I want to expose the values in the datagridview, and I can not work out what is turning off the fields.



DataSet dataset1 = new DataSet();


dataGridView1.DataSource = dataset1.Tables[tableName];

Open in new window

Question by:rowansmith
    LVL 21

    Expert Comment

    Does your gridview have autogeneratecolumns set to "off"?
    LVL 7

    Expert Comment

    Can you attach an example XML file that your are using?
    LVL 11

    Accepted Solution

    It is a default datagridview I do nothing to it except the code you see (assign the datasource), according to the debugger autogeneratecolumns is set to true.

    The XML files are too large to post, and I really do not want to try and trim them down to an example because it will not be a real example.

    dataset1.ReadXML(Filename) results in a dataset consisting of 52 tables, parent tables and child tables and tables to maintain many-to-many mappings.

    After analysing the datacolumn objects in each datatable in the dataset I have determined that the value of the datacolumn.ColumnMapping is set to MappingType.Hidden.

    It would appear this is done so that when the XML is written out again, (dataset.writexml) these values are not written out because they are internal.

    The datagridview does not show these, setting columnmapping to mappingtype.element solves the problem and I can see the columns in the datagridview.

    LVL 21

    Expert Comment

    What happens if you set the AutoGenerateColumns to "False"?
    LVL 21

    Expert Comment

    Sorry, ignore the previous comment.
    LVL 11

    Author Comment

    So can you help me with this, realise it is a completely different question if you can not help I will close this one and start a new one...

    After ReadXML I have the following (that I am going to care about).

    dataset1.Tables["service" , "members", "reference"];

    So three tables which are related ....

    Each tables columns/fields looks like this
    service (name, service_id)
    members (members_id, service_id)
    reference (name, Table, members_id)

    These three tables facilitate a one-many mapping of "one service"  has "many references" effectively - that much I have been able to work out...

    So an example of the data looks like this:

    AOL_Messenger  36
    Authenticated 37
    ClearTrust  40

    0 36
    1 37
    4 40

    AOL 0
    ICQ_locator 0
    telnet 1
    ftp 1
    http 1
    login 1
    Trust-Auth 4
    Trust-Dispatch 4
    Network 4

    So in effect I have three parent objects which each has child objects like this:




    I want to create a datatable that has the on the left and the on the right.  How do I do this?  I notice that the dataset has quite a few DataRelation objects already created but I do not know how to integrate with these?



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    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