howto set "display" text of dg Column headers @ design time?

hi,
I have a datagrid that pulls data from the database.
the fields in the db are as follows:

1) companyId
2) companyName
etc

This casues the headers to appear as:
1) companyId
2) companyName
etc

...not very neat :-(

I want the column headers in the datagrid to be:
1) Company ID
2) Name
etc

IOW, I want to be able to assign the text for the column headers, via the designer.
This was quite easy in asp.net grids, using the property builder.
Can it be done in winforms grid
If not, is it possible to do at runtime

cheers, 
yogi


Answer this question

howto set "display" text of dg Column headers @ design time?

  • Loknar - DBA

    hi Bloke,
     
    Thanks for the suggestions.I have followed your instructions, yet the friggin headertext is still the same as before.

    <rant>
    I'm fairly new to winforms, but not dotnet.I can't believe how difficult it is to simply assign a different headerText to a datagrid column.I now understand why robert mclaws went nuts when he first tried to do things in winforms.
    <\rant>

    Sorry for the rant, but I feel like a donkey :-)
    Anyway, In the designer, I can see the datagrid, and it contains the original, unformatted headeText columns.

    I choose:
    properties >tableStyles > Collection > Add
    In the "misc" section I can successfully view the "mappingNames" that are contained within the typed dataset. (so, I believe, so far so good :-) )

    Then,  I change the "headerText" for a column, and still, the colums appear exactly the same crappy text that they've always had, even at runtime.

    Can you see where I'm going wrong I'm sure it must be something simple.

    Many thanks.
    yogi 


  • prudhvi

    Hi bloke, 
    Sorry, I don't follow you.I should explain.
    I bind my datagrid to a funtion that returns a datatable.This datatable:

    1) does not directly represent a single database table.
    2) is created thru a stored procedure that contains inner joins.

    With this in mind, is your advice still the same

    At the moment, I have:
    1) Clicked on the TableStyles property of the DataGrid and create a new table style.
    2) Dropped a dataset onto the form

    ..In the DatagridTableStyle Collection Editor I can see the MappingName, but I really don't see how this relates to a dataset that I have randomly dropped onto my form.

    Sorry to be a pain, but I can't see where I'm going wrong.Should I modify my approach

    All suggestions appreciated.
    Thanks, 
    yogi


     

  • HLDev

    Your approach looks fine.  The advantage of assigning a mapping name will help you create the ColumnStyles.  You can actually create the TableStyle in code which gives even more flexibility.  I am assuming that the datatable the method (function) returns is the same as that of the SP.

    try
    1. Add a dataset componant to your project (Project/Add Component...\Data Set)
    2. Open up your Server Explorer and navigate to the SP you wish to use.
    3. Drag and drop the SP onto the designer of the DataSet xsd file you have just created.
    4. Open the form in designer view and from your toolbox drag and drop a dataset object onto the form.  An "Add Dataset" dialog should appear with the "Typed Dataset" radio button selected and the name of the dataset you just created in the textbox box.  Click OK
    5. Select the DataSource property of the DataGrid and you should now be able the select the DataTable you just created in the Dataset.

    Now continue selecting the MappingName and creating the StyleCloumns so that you can change the header text.

    Just make sure the DataTable you return has the same name as the datatable you selected in the Dataset.

    RAD

  • Graham Parker

    I don't know whats wrong now, It should work, are you sure that the datatable you are returning has the same name and structure as the datatable your mapping to.
    maybe try
    MyDataSet.MyDataTable.Clear();
    MySPDataAdapter.fill(MyDataSet.MyDataTable);
    or
    MyDataSet.MyDataTable = MyFunction();

    MyDataGrid.DataSource = MyDataSet.MyDataTable;

    And see if that works otherwise give up :) and alter your SP to something like
    Select MyField as 'My Field' from...

    As per the snippet above I generally populate a datatable with a DataAdapter

  • Pablo A Castillo

    Click on the TableStyles property of the DataGrid and create a new table style.  You'll need to drop a dataset onto the form designer to pick the Tables MappingName property.  Then select the GridColumnStyle property to create columns.  Set the MappingName to the column and the HeaderText.

    Easy

  • DMOORE

    hi bloke, 
    I can't work it out either.I'll just go with using aliases at the minute and then work out where I'm going wrong.I've found a decent article that explains a bit more of the ins and outs of the datagrid..I hope it's useful to others...
    http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/datagrid.mspx

    I'll get to the bottom of it and post where I went wrong..as they say in Oz, "she'll be right" :-)

    thanks bud, 
    yogi

  • howto set "display" text of dg Column headers @ design time?