Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Serializing Dataset to a stronglytyped Property
Message
From
14/11/2009 20:09:28
 
 
To
14/11/2009 17:25:31
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
VB 9.0
Miscellaneous
Thread ID:
01434726
Message ID:
01434794
Views:
34
Oh wow, where to start?

Well, first, I am definitely *not* a DataGridView guru, not even close. About a year ago I started messing around with creating our own Grid sub-class for our Framework, but never completed it ... a new guy at our company kept insisting on using the DevExpress grid rather than create our own and he got his way. So, unfortunately I never did get much experience with the grid (I was the Team Lead for our Platform Team, which dealt with our Framework and other "platform" stuff to support the application developers, so I didn't really get to use the grid). But, I will say that the DevExpress grid seems to have a lot of nifty bells and whistles.

Now that said, I don't think you should need to be un/re-hooking up the Grid's DataSource ... don't know why you had problems with the .EndEdit() not working. Question ... is the DataSource the DataTable itself or did you set it to a BindingSource? Rather than a grid.EndEdit(), perhaps you should try a bindingsource.EndEdit()?

>I created my dataset by dropping a dataset on the form and doing everything with properties. I would prefer the dataset be strongly typed, but I didn't know if that were an option the way I am doing it ( I obviously cannot create a strongly typed ds by creating it from a data structure as there isn't one beneath the presentation layer.)
>
>How would I create a strongly typed ds? Should I cut the code from the form designer blow away the component and create the ds as a class, adding the typing attributes or can I still do it fiddling props? I see some props in the column collections but i'm not sure that's the same thing.


I would have a DataSet project that contains nothing but Typed DataSets. To create one, you start off with an .xsd. To start doing that, when you go to add a new item to a project, choose DataSet from the item templates. That'll get you the .xsd designer and all that. Once you've designed the DataSet (which you can do manually, or drag tables or Stored Procs from a database in the Server Explorer), the dataset generator will generate a typed class for you (you may have to change the .xsd's CustomTool property in the Property Sheet to specify MSDataSetGenerator). Now, the only problem with recent versions of VS is that it adds a lot of crap (IMHO) to the .xsd now that it didn't used to do. It'll also add TableAdapters, also crap in my book. It didn't used to do any of this prior to VS 2005. I used to have a little utility for easily generating .xsd's from Stored Procs (one that Gary wrote years ago) ... I'll see if I can dig it up (no idea where it is ... I've changed computers several times since I've used it). Currently, if you have a plain vanilla .xsd (without the crap) and you only edit the XML and don't go ever make changes from the visual designer (and don't save if you have the designer open), it won't generate the crap in the .xsd.

So, anyway, once you have the .xsd, and you've edited the XML and you save, that's when the MSDataSetGenerator generates your strongly-typed class. Whew. That's a lot. Hope you get what I'm saying.

For now, maybe you can live with the extra crap in your .xsd (maybe there's a way to turn that off? I don't know), but I'll try and see if I can find something to make the .xsd creation a little bit easier.

~~Bonnie




>You really put me on the right track. DataGridviews and Datasets are completely new to me so I'm just learning their tricks. I believe the serialize/deserialize code I posted the link to is working fine and my problem was - as you suggested - to do with needing an endedit() on each grid before serializing (first time I was even aware of the method )
>
>
>    Private Sub CompaniesBO1_BeforeSave _
>(ByVal e As MicroFour.StrataFrame.Data.BeforeSaveUndoEventArgs) _
>Handles CompaniesBO1.BeforeSave
>
>        Me.dtgGL.EndEdit()
>        Me.dtgProp.EndEdit()
>        Me.dtgGL.DataSource = Nothing
>        Me.dtgProp.DataSource = Nothing
>
>        Me.CompaniesBO1.WideXML = Me.SmartSerialize(Me.ChildDataset)
>        Me.ChildDataset = Me.SmartDeSerialize(Me.CompaniesBO1.WideXML)
>
>        Me.dtgGL.DataSource = Me.ChildDataset
>        Me.dtgProp.DataSource = Me.ChildDataset
>
>    End Sub
>
>
>(the unhooking an rehooking the datasource seems like overkill, but I think I was having trouble getting it to work otherwise - if it looks weird to you I'll revisit it )
>
>Now questions on Datasets and Gridviews :
>
>I created my dataset by dropping a dataset on the form and doing everything with properties. I would prefer the dataset be strongly typed, but I didn't know if that were an option the way I am doing it ( I obviously cannot create a strongly typed ds by creating it from a data structure as there isn't one beneath the presentation layer.)
>
>How would I create a strongly typed ds? Should I cut the code from the form designer blow away the component and create the ds as a class, adding the typing attributes or can I still do it fiddling props? I see some props in the column collections but i'm not sure that's the same thing.
>
>On the gridviews: How do you do stuff like formatting and validation? ie. decimals, dates, integers etc. i can get a checkbox for a boolean but so far that's about it except letting it blow up if i type in an invalid date after saying the column was datetime.
>
>Is there a way to preset the max number of rows?
>
>Is there some opensource better gridview I should just start using now (or one to buy that is really worth it even for this basic stuff ) or can this simple stuff be done easily with the Datagridview if you are not as ignorant as I am? I will be researching this on my own, of course, but any wisdom/tips from you, Cetin (and any of the million other folks who know more about this stuff than I do :-) always welcome.
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform