IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New You're overlooking
how the Datagrid control in VB.Net is supposed to be exactly the same one in ASP.Net (at least, according to Microsoft).

When assigning a dataset to a grid by using

Grid.Datasource = dataset retrieved from SQL table

in an ASP.Net program (using VB.net as the "code behind"), it does not require ANY TableStyle or GridColumn properties to be set - it displays the data proportionally AUTOMATICALLY. Using a datagrid in a VB.Net Windows Forms program DOES. And doing it in the code DOESN'T work; you have to click and set properties at design time.

And that's the source of my frustration.
lincoln

"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from." -- E.L. Doctorow


Never apply a Star Trek solution to a Babylon 5 problem.


I am not merely a "consumer" or a "taxpayer". I am a Citizen of the United States.


[link|mailto:bconnors@ev1.net|contact me]
New You've got your mappings wrong
If you are ChicagoBoy and [link|http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.datagridcontrol/browse_frm/thread/8777eb1801fc8510/216709814fc7d3f0?lnk=st&q=datagrid+proportionally&rnum=7#216709814fc7d3f0|this] is your post then...

a) This code doesn't compile becuase Tables is not a member of SqlDataAdapter. I think you meant MyDataset.Tables(0)
b) You map the 2nd column to ProductDesc when it's called ProductName in the SQL query.

If this wasn't you or if these were transcription errors then I apologize but it does look just like what you are talking about, so lets move on.

The problem lies in these two lines:
MyDataset = New DataSet("Products")
MyDataAdapter.Fill(MyDataset)

The first line names the Dataset "Products"
The 2nd line doesn't name the table within the Dataset so it gets assigned a default name "Table". Further down you set myGridStyle.MappingName = "Products". That doesn't match "Table" so your style gets ignored. You should either set the MappingName to "Table", or better yet, change your Fill call to:
MyDataAdapter.Fill(MyDataset, "Products")
You might consider naming (the string name) your Dataset something else to avoid confusion.

As to why this is so complex and different from ASP.Net's Datagrid? The WinForms datagrid supports drilling down into hierarchical data, so it has support for these mappings so that the appropriate styles and column settings can be retrieved as the user drills into the data. The ASP.Net DataGrid doesn't have this feature.

As to why the WinForms DataGrid doesn't support proportional column sizing? My guess is they didn't want to have to loop thru all the column values, measuring each's length with the current font. ASP.Net's DataGrid can get away with this because:
a) It's made to display data in pages of limited length.
b) The browser can size the columns based on the generated HTML

The .Net 2.0 DataGridView has options for autosizing columns based on content or by setting relative weights for each column. It also doesn't do the hierarchical thing so you have one less level of abstraction to worry about
--
Chris Altmann
Expand Edited by altmann March 30, 2006, 01:29:35 AM EST
New On to the future!

The .Net 2.0 DataGridView has options for autosizing columns based on content or by setting relative weights for each column. It also doesn't do the hierarchical thing so you have one less level of abstraction to worry about


I looking forward to convincing my boss to go to .Net 2.0, so I don't have to keep jumping through these hoops. He'll probably agree, as long as it doesn't cost us too much out-of-pocket.

BTW, I tried your code suggestions - it still doesn't work. Pisser.

lincoln

"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from." -- E.L. Doctorow


Never apply a Star Trek solution to a Babylon 5 problem.


I am not merely a "consumer" or a "taxpayer". I am a Citizen of the United States.


[link|mailto:bconnors@ev1.net|contact me]
New Might take a look at this too
Be aware (beware) that VS.Net 2005 is somewhat designed for SQL Server 2005. It sounds like you can still use it with SQL Server 2000, but I don't know what pitfalls await there (MS tying products together?!? Shocking!). ASP.Net 2.0 is quite different from ASP.Net 1.1 as well. Fortunately you can run VS.NET 2003 and VS.NET 2005 side by side.

If you can solve whatever other problems you are having with the DataGrid, here's how to do autosizing of columns with the DataGrid: [link|http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q877q|http://www.syncfusio...Q_c44c.aspx#q877q] That FAQ is a good reference overall for WinForms programming.

In case we missed something else, here's the code based on yours that worked for me with a empty form on which I dropped a DataGrid named DisplayGrid and a OleDbConnection named objCon. I also used an Access DB instead of SQL Server. And I've excised the designer generated code (which BTW, is where all that point and click config of the DataGrid from my original solution would appear as code).

\nPublic Class Form1\n    Inherits System.Windows.Forms.Form\n\n#Region " Windows Form Designer generated code "\n...\n#End Region\n    Dim MyDataAdapter As System.Data.OleDb.OleDbDataAdapter\n    Dim MyDataset As System.Data.DataSet\n\n    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\n        Dim strSQL As String\n\n        strSQL = "SELECT DISTINCT ProductCode, ProductName FROM Products"\n        strSQL = strSQL & " WHERE ProductName IS NOT NULL ORDER BY ProductName"\n        MyDataAdapter = New System.Data.OleDb.OleDbDataAdapter(strSQL, objCon)\n        MyDataset = New DataSet("ProductsDataset")\n        MyDataAdapter.Fill(MyDataset, "Products")\n        DisplayGrid.DataSource = MyDataset.Tables("Products")\n\n\n        Dim myGridStyle As DataGridTableStyle = New DataGridTableStyle\n        myGridStyle.MappingName = "Products"\n        ' \n        '     The ProductCode is a 3 byte varchar field \n        ' \n        Dim myFirstColumn As DataGridColumnStyle = New DataGridTextBoxColumn\n        myFirstColumn.MappingName = "ProductCode"\n        myFirstColumn.HeaderText = "Code"\n        myFirstColumn.Width = 40\n        myFirstColumn.Alignment = HorizontalAlignment.Center\n        ' \n        '     The ProductDesc is a 50 byte varchar field \n        ' \n        Dim mySecondColumn As DataGridColumnStyle = New DataGridTextBoxColumn\n        mySecondColumn.MappingName = "ProductName"\n        mySecondColumn.HeaderText = "Name"\n        mySecondColumn.Width = 400\n        mySecondColumn.Alignment = HorizontalAlignment.Left\n\n\n        myGridStyle.GridColumnStyles.Add(myFirstColumn)\n        myGridStyle.GridColumnStyles.Add(mySecondColumn)\n\n\n        DisplayGrid.TableStyles.Add(myGridStyle)\n    End Sub\nEnd Class\n


Good luck!
--
Chris Altmann
New VS 2005 (.NET 2.0) cost depends on the level
Professional isn't too bad (<$500/seat upgrade), and I guess Enterprise Developer (VS2005 ED) might not be too bad if you're already paying for MSDN Premium, otherwise it's way more expensive than before - at about $2300/seat upgrade - since you have to get it with MSDN Premium.

VS2005 Enterprise Kitchen Sink is about $10,000/seat, not including the various server thingies (TeamServer?)

We have VS2001 Enterprise Developer, looked at the price to upgrade to VS2005 ED, laughed, and upgraded to VS2005 Professional. I saw no value in VS2005 ED, since all the interesting extras have open source equivalents that are probably better (e.g. Subversion for version control, NUnit for unit testing).

The big advantage of .NET 2.0 is, of course, being able to run IronPython.

--Tony
     Datagrids suck/don't suck in .NET - (lincoln) - (17)
         They do suck, but try this - (altmann) - (16)
             So this is easier than writing your own HTML? -NT - (drewk) - (1)
                 To create a editable grid in a Windows program? Yes. -NT - (altmann)
             That worked, but I prefer to do things in code - (lincoln) - (13)
                 Like I said, this (datagrids) is easier than writing code? -NT - (drewk) - (6)
                     Oh, come the heck on! Six or eight drop-down selections! - (CRConrad) - (5)
                         My experience with it - (drewk) - (3)
                             Again, we're talking about client side Windows apps here. -NT - (altmann) - (2)
                                 Come on, let me slam Winders, please? - (drewk) - (1)
                                     Like shooting fish in a barrel - (ChrisR)
                         BTW, I just checked: In Delphi, it's zero properties to set. - (CRConrad)
                 So do that. - (altmann) - (5)
                     You're overlooking - (lincoln) - (4)
                         You've got your mappings wrong - (altmann) - (3)
                             On to the future! - (lincoln) - (2)
                                 Might take a look at this too - (altmann)
                                 VS 2005 (.NET 2.0) cost depends on the level - (tonytib)

Got root?
67 ms