DataGrid Settings Change

TedN

Freshman
Joined
Sep 25, 2006
Messages
35
I've created a data grid with the form designer and set the various column widths and headings. However, when I display the data in the data grid the column widths change back to the default and the headings are the database column headings.

The code I'm using to display the data grid is:

Code:
Me.dg1.DataGrid.DataSource = ds.Tables("Asset1")

where dg1 is the data grid and ds the dataset.

The only way I can find to get the right headings is to define them in the sql string.

How can I keep my original data grid settings which I did in the form designer.

Thanks,
Ted
 
I'm not sure, but I believe that if you use the Form Designer to edit the style of the DG you must use the Form Designer Bound Data Control to maintain the style. If you setup the style through code I think it'll stay.
 
From my experience. If you decide to design your datagrid during design view then you should also set the datasource during design view. It is clear from your code that you're setting the datasouce through your code. If you set your datasource during design view then the last thing you must do is Fill your datasource. No more setting the datasource through code.
 
Thanks Amir.

I've now done everything during design time and the only code I have is:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        con.Open()
        da.Fill(ds, "Test")
        con.Close()

    End Sub

This works fine but how do I assign different column widths to the datagrid.
TableStyles gives me a preferred column width which applies to all columns.

If I add a Member in TableStyles then add GridColumnStyles Members each with its own width, it is totally ignored. I'm obviously out to left field here.

Also, each time I click the button the data repeats itself. Anyway to clear the datagrid.
I've tried ds.Tables("Test").Clear() which stops the repeat but the datagrid isn't updated.

Thanks,
Ted
 
Yup. That should do it.

I've also sorted out the data repeat. The table was updating when I used ds.Tables("Test").Clear(). I was being lazy and instead of actually changing the data in the datagrid and then clicking the button I simply did a sort to change the data around.

Thanks,
Ted
 
Back
Top