Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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

Posted
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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

Have a look at the following site, it will provide you hopefully with the information you require.

 

http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx#44

 

Hope this Helps

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
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.
Amir Syafrudin
Posted

Thanks Amir.

 

I've now done everything during design time and the only code I have is:

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...