How to translate this Invoke/Delegate

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to translate this Invoke/Delegate

Post by wriedmann »

Hi Dick,
may I suggest to newer use DataTables as Datasources to grids, but always ObservableCollection objects? That makes you much more flexible in the display of data, and when you are changing one record, you have only to change one element of your collection, and not rebuild the entire data.
Wolfgang
 
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to translate this Invoke/Delegate

Post by ic2 »

wriedmann post=27242 userid=336 wrote:Hi Dick,
may I suggest to newer use DataTables as Datasources to grids, but always ObservableCollection objects? That makes you much more flexible in the display of data, and when you are changing one record, you have only to change one element of your collection, and not rebuild the entire data.
Wolfgang

 
Hello Wolfgang,

Sounds good; I'll have to figure out how to assign a SQL cursor to a OC and also see if that speeds up things. The rebuild is visible so certainly not instantly. Not sure if that changes if e.g. a few new lines are added and possibly some lines changed in one or more cells but worth to give it a try.

Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to translate this Invoke/Delegate

Post by ic2 »

Hello Chris,
Chris post=27241 userid=313 wrote:  

You are right. First a query is built based upon user choices to show e-mails. Then the query is executed + assigned to the DataGrid with the above code. The same code runs from the timer (the reason for the exception) which is a refresh of the browser with possibly new mails in it. So it needs to rerun the query. I am not sure what I should do differently? If I do not assign the datasource with every refresh, it won't show added or changed data I'd say?

I have to add that I have left the program open the whole day without the crash. This can still be a coincidence of course but I think so far it has always crashed well before the the day was over. So maybe the Invoke line did it's job.....

Dick
User avatar
Chris
Posts: 4907
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to translate this Invoke/Delegate

Post by Chris »

Hi Dick,

Oh, that's great, if the invoke() indeed fixed the issue, then that's very good news! Hope it stays like that!

As for what's the best way to deal with those situations, I'll let the guys like Wolfgang who are much more knowledgeable than me in this area to give you further suggestions.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to translate this Invoke/Delegate

Post by wriedmann »

Hi Dick,
you will have to do that manually.
Normally my models (the items that are composing such a collection) have a method "FillFromRow()" that takes a DataRow object as parameter and fills the fields from it.
On the other side I have some classes that internally are using a dictionary as data storage and the properties are accessing the values through this.
In this manner I can read the data in a loop (when there are many fields). But very often the data comes from different sources (different databases or even from DBF sources).
And when the data is changed, a SQL update or insert statement is built and executed against the database.
This is for sure more work and more complex than directly using a SQL cursor or a datatable as the grids datasource, but gives much, much more flexibility and power and is also faster on execution.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to translate this Invoke/Delegate

Post by ic2 »

Hello Chris, Wolfgang,

Thanks for the directives. I will put a couple ToDo's in the code - hmm, I realize there is in rare cases something I like in VS :)

Also this has been the 2nd day that the program didn't crash after the Invokce addition. Could still have been random luck and tomorrow  or so I have to tell that it crashed again - but I think it always crashed before, latest at the end of the afternoon.....

Dick
Post Reply