WPF and databinding in a multi threaded ADO.NET app - c#

I need advice and clarification please. I'm currently working on a monitor app that needs to show the contents of a database in a datagrid (I'm using the WPFToolkit grid btw). The grid binds to a table in my ADO.NET DataSet and it works fine. If I modify the DataSet through a button in my UI the grid updates and everyone is happy (binding and ADO.NET is nicely described in this blog). However, the database will be updates by other applications and the monitor app needs to display those changes automatically. The DataSet is updated through polling the database (for various reasons listening to post_events from the DB is not applicable) but the changes are not displayed in the grid.
As far as I have understood this is a feature of WPF databinding. You cannot update the source from another thread than the UI's. In my mind this is insane. There must be thousands of apps out there where data is entered from another user or application. I have tried using the Dispatcher to move the actual updating of the source to the UI thread but I still get the same error.
So now to my question: Is my analysis correct and if so can you offer any advice on how to solve the problem? Also if my analysis is correct can someone please try to explain why WPF works like that?
Thank you for your time

Probably! not the solution to your problem but have a look here http://weblogs.asp.net/cschittko/archive/2008/05/14/wpf-ui-update-from-background-threads.aspx, it might give you some more avenues to look at.
Another link is here wpf: update multiple controls via dispatcher
HTH

After doing even more research I have found my analysis to be correct. While I haven't figured out a way to make it work within ADO.NET I did find a good solution here that uses a simple derivate of ObservableCollection.
Using the RowChanged event from the DataTable I keep track of a BindableCollection view of the table and use that as my DataContext. Works like a charm.

Related

DataGrid in asp.net using c#

My question might be little strange but I am new to web - based programming. In windows based application, if I need to let the user to edit and view the table then I am using the datagrid. In web - based, there is GridView but it is read only tool. I want to see if there is any tool like this in asp.net. Can you please help?
Thanks
Have a look on the ListView control, basically, It lets you specify methods to show, update, edit and delete records from your datasource.
There are a lot of examples for it. Here's a nice article
If you want your end users to have a little bit better experience then you should consider the alternative to use a javascript based grid, which is a more modern way to build a grid. Then everything executes smoothly in the web browser without the need to post back and reload the page, and the server will only be called when it's really necessary (loading data, saving data) but not when you change a row when it´s being edited, or if you do incremental searches.
My favorite is the Slickgrid. And here is a cool Slickgrid example with Async post rendering.
If you choose the server control way (ListView etc) you will have a lot of postbacks every time you sort, change editing mode in cell or edit data.
Look at this question if you want some more examples of javascript grids.

Datagridview in winforms application updated automatically when there is any change in database

I am working on a winforms c# application which is using the technologies like Entity Frame work-code first.i have to make a form in which records from database continuously should shown.first i apply a simple timer technique which updates Grid and other control after 5 sec. but it is too much expensive and eat resources.
i want to ask is there any other sophisticated method by which data in DGV and other controls automatically updated if any change happen in Database.
http://dotnet.dzone.com/articles/c-sqldependency-monitoring
Look into SQLDependency. It is designed for this exact scenario.
There is a DataChanged event handler.
I used it very recently on a project for showing 'live' data from our TFS server and it's working very well.

How would I create a table control similar to the one shown?

I've got a table from an existing LabView VI (ewww!) that I need to replicate in C#. The table is shown in the image below. Each field will be populated with data returned by status queries to an external device, likely from within a dedicated status thread (when I implement it...). Is there any control, or direction I should take when extending an existing control for the table-like display of my query results? DataGridView seems like overkill for this, but the table layout container populated with TextBox controls seems inelegant. I'd like some insight, if anyone can offer it. Also, please feel free to shut me down if this has been asked already (though my search turned up nothing I could relate to...). Thanks.
DataGridView is the only suitable control here. Anything else either doesn't have enough grid editing capabilities (like ListView) or is fugly-slow like individual controls in a TLP.

Update DataGrid WinForm control in .Net 2003

I've been using VS 2005 and VS 2008, and never asked this question, but now I'm having a hard time using controls in VS 2003. A dataGridView does not exist, and I'm forced to use DataGrid control to show some data. The problem is, that I want to edit some of the values displayed by this control, and to reflect those changes in database, and I'm not finding a way to achieve this. Already "googled", no relevant results found, so please give me some little help. I'm coding in C#.
There's a reason that DataGrid was replaced with DataGridView... I expect you'll need to find a 3rd-party grid control for 1.1 to do this (but that gets harder the older 1.1 gets).
Sorry if this isn't very helpful...
you can use SqlDataAdapter to fill your DataSet and bind this DataSet to DataGrid and after your changes are made on the DataGrid just call SqlDataAdapter.Update method to update the database
I got a link from google, as a new user I am not able post it, when you google with 'DataGrid Windows msdn' words the first result have an example make sure that you change the version of the msnd to 1.1 framework.
Hope this helps.
You can use a listview to list the data from database. You can bind the itemsource of listview to a list which you get from DB. Also you can make the listview editable.
If the listview is not sufficient, you can use WindowsFormHost like
System.Windows.Forms.FlowLayoutPanel advancedFlowLayoutPanel =
this.flowLayoutHost.Child as System.Windows.Forms.FlowLayoutPanel;
advancedFlowLayoutPanel.WrapContents = true;
Inside it you can place DataGrid.

Advanced GUI and database in c#

Do you have any idea how to present all rows from let's say table with the possibility to click on particular row and open that way another window to edit?
I've got no idea how to create this. I would like to avoid access like creation by built-in wizards in Microsoft Visual Studio 2008.
Perhaps you know where I can find more information.
Execute a query which retrieves an overview of the records that you want to display.
When you double-click a row, you retrieve the records that represent that entity, and display it in another window...
That's in a nutshell how you could do it.
For a web application you may want to look at this Walkthrough as MSDN. You can find a winform walkthrough at MSDN as well. Though you say that you prefer doing it without the designers, I suggest that you go through the walkthrough using the designer and look at the code that it produces as a sample of how you could do it by hand. You could then adapt the example as needed for your purposes. For more references try googling "master detail view."
well i would use wpf with a stackpanel of listboxes
the rows are dynamically added to the stackpanel.
the listboxes contain textfields that are databind -ed to mouseclickevents and onchanged events.
http://dotnetslackers.com/articles/silverlight/WPFTutorial.aspx

Categories

Resources