Page 2 of 2
How to translate this Invoke/Delegate
Posted: Sun Aug 06, 2023 9:46 am
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
How to translate this Invoke/Delegate
Posted: Mon Aug 07, 2023 8:33 pm
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
How to translate this Invoke/Delegate
Posted: Mon Aug 07, 2023 8:37 pm
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
How to translate this Invoke/Delegate
Posted: Mon Aug 07, 2023 11:01 pm
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.
How to translate this Invoke/Delegate
Posted: Tue Aug 08, 2023 3:52 am
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
How to translate this Invoke/Delegate
Posted: Wed Aug 09, 2023 8:35 pm
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