TedN Posted March 2, 2007 Posted March 2, 2007 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 Quote
Nate Bross Posted March 2, 2007 Posted March 2, 2007 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
TedN Posted March 4, 2007 Author Posted March 4, 2007 Thanks Nate. I'll try coding the style. Ted Quote
SonicBoomAu Posted March 5, 2007 Posted March 5, 2007 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 Quote 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
amir100 Posted March 5, 2007 Posted March 5, 2007 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. Quote Amir Syafrudin
TedN Posted March 6, 2007 Author Posted March 6, 2007 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 Quote
SonicBoomAu Posted March 7, 2007 Posted March 7, 2007 Try the following: http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q792q Or http://www.xtremedotnettalk.com/showthread.php?t=91566 Quote 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
TedN Posted March 7, 2007 Author Posted March 7, 2007 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.