Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Casting strong type DS as dataset
Message
From
14/12/2009 13:51:00
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01438526
Message ID:
01438976
Views:
45
The row is there, just not the value of the current, dirty cell.

I've tried the endedits before and after the Acceptchanges. It laughs a me..
Seems the problem is that the current cell which is dirty will not commit - even with endedits, until the cell loses focus. Clicking a save button doesn't fire the event to deselect the cell.

http://stackoverflow.com/questions/963601/datagridview-value-does-not-gets-saved-if-selection-is-not-lost-from-a-cell

If I click on another control before clicking the save all works as expected. Oddly, calling txtCompany.focus() in my beforesave handler does no good.

The solution offered on SO for the question above involves knowing the name of the grid that might have a dirty cell. I have 20 of these grids and the user could be in any on one of them when clicking save. Toolstrip click handler does not know the current control ( I don't think ) when it is called. I am now going to investigate finding out from the form what has selection when the save is called ... that may be the answer.


>Don't think I can help here - Winforms is pretty much off my radar :-{
>FWIW, I'd assume that the row is actuallly missing when you call the Serialize() but you coudl check just to narrow it down.
>
>Also (completely left-field) you could try doing the EndEdits() before the AcceptChanges().......
>
>
>>Hi Viv -
>>
>>Sorry I didn't reply to this sooner but that answer was, at the time, I don't know. i had run off in so many different directions chasing this that I wasn't sure which parts worked and which didn't.
>>
>>i think now the answer is that I have solved the serialization, which turned out to be easier than I was making it ( code below for lurkers ) and now have it reduced to a problem with Datagridviews using the dataset member as a datasource. (explained below and my current source of frustration)
>>
>>That first :
>>
>>I created a small test app with one table, three columns
>>ikey int pk
>>company varchar(100)
>>wideobject varbinary(max)
>>
>>I have a dataset (Typedchildset) with two datatables ( Clients, Employees)
>>
>>I have 2 dgvs. For simplicity, I am binding them to the dataset member rather than using a binding source
>>
>>I enter data the two grids - Clients, then Employees.
>>
>>Everything saves when serialized as expected - except the last new row of the last grid.
>>
>>I can add five rows to employees and all save the last will be saved.
>>
>>NOTE : on further testing - the problem only comes about if the cursor is still in the newly added row when the save is called. If I first click out of the grid to another control, then save, the last row is saved. But of course, the use won't do that, so i must force something so the endedit actually ends the edit for that row.
>>
>>In the BeforeSave event of my business object :
>>
>>
>>
>>'Tried me.txtCompany.focus() before the code below, as actaully clicking the textbox to get out of the grid before clicking the Save button seems to work - no joy
>>
>>' I found I needed this before the endedits or I also lost the last new row of the first grid
>> 
>>      Me.TypedChildset1.AcceptChanges()
>>
>>        Me.dgvClients.EndEdit()
>>        Me.dgvEmployees.EndEdit()
>>
>>' 
>>
>>' Here's the serializer - works fine ( note : remotingformat prop of ds instance must be 
>>' set to binary
>>
>>        '-- Copy dataset to property
>>
>>        '-- Establish locals
>>        Dim loFormatter As New BinaryFormatter()
>>        Dim loStream As New System.IO.MemoryStream()
>>
>>        '-- Serialize the business object
>>        loFormatter.Serialize(loStream, Me.TypedChildset1)
>>
>>        '-- Return the created stream
>>        Me.CompaniesBO1.WideObject = loStream.ToArray()
>>
>>
>>Feel I'm getting very very close, but this last bit is making me crazi(er).
>>
>>Thoughts?
>>
>>
>>>Hi,
>>>Did you solve this?,
>>>Best,
>>>Viv
>>>
>>>>I have a varchar(max) field in SQL 2008 Dataset_XML. My strongly typed business object is mapped to that column, and returns
>>>>
>>>><dsPolicies xmlns="http://tempuri.org/dsPolicies.xsd" /> 
>>>>
>>>>for a null. ( this is because I am adding this field to a current app an have to allow nulls, but I could script this as a value for all null values and then not allow nulls if that would help)
>>>>
>>>>dsPolicies is dropped on the form and the instance is names dsPolicies1.
>>>>
>>>>The dataset is typed with 8 tables. and the XSD file seems to be working as I am using bindingsources for each table and the datagridviews are showing the right columns.
>>>>
>>>>In the parentform_loading event of the business object on the Policies form I am trying to deserialize the XML stored in Me.PoliciesBO1.Dataset_XML ( which has the default value shown above) using this code :
>>>>
>>>>
>>>>    Private Sub PoliciesBO1_ParentFormLoading() Handles PoliciesBO1.ParentFormLoading
>>>>
>>>>        Me.PoliciesBO1.fillall()
>>>>
>>>>        If Me.PoliciesBO1.Count > 0 Then
>>>>
>>>>            Me.DsPolicies1 = _ CType(InsurtecPW.Base.Utility.SmartDeSerialize(Me.PoliciesBO1.Dataset_XML), InsurtecPW.dsPolicies)
>>>>
>>>>        End If
>>>>
>>>>    End Sub
>>>>
>>>>
>>>>and this is the deserialize routine :
>>>>
>>>>    Public Shared Function SmartDeSerialize(ByVal serialized As String) As DataSet
>>>>        Dim __ds As DataSet = New DataSet
>>>>        ' needed to create an XML TextReader 
>>>>        Dim nt As NameTable = New NameTable
>>>>        Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nt)
>>>>        Dim context As XmlParserContext = New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)
>>>>        Dim tr As XmlTextReader = New XmlTextReader(serialized, XmlNodeType.Document, context)
>>>>        Try
>>>>
>>>>            __ds.ReadXml(tr)
>>>>
>>>>            Return __ds
>>>>        Finally
>>>>            If Not (tr Is Nothing) Then
>>>>                tr.Close()
>>>>                tr = Nothing
>>>>            End If
>>>>            context = Nothing
>>>>            nsmgr = Nothing
>>>>            nt = Nothing
>>>>
>>>>        End Try
>>>>
>>>>    End Function
>>>>
>>>>
>>>>As you see, this returns a dataset, but I don't seem to be able to cast the return value as the dsPolicies that I need.
>>>>
>>>>Unable to cast object of type 'System.Data.DataSet' to type 'InsurtecPW.dsPolicies'.
>>>>
>>>>I have also tried a directcast of the returned dataset and got the same result.
>>>>
>>>>This approach seemed to work find when I was using an untyped dataset.
>>>>
>>>>I'd appreciate any thoughts on this. I'm pretty clueless about possible differences between the dataset class and a typed dataset or if my problem is the value I am returning if the column is empty.
>>>>
>>>>I am open to any approach (including serializing to a byte array) which will allow me to write and entire dataset to a sql column and bring it back.
>>>>
>>>>Suggestions very much appreciated.
>>>>
>>>>TIA


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform