Datagrid Edit Windows Form - database

I have worked in ASP.net before and know that I can edit its equivalent to a datagrid (detail view or something like that?) However, I'm working on a windows form now and i need to use the datagrid. I know there are options to edit each individual cell and when I ran my program, it edited it, but it does not update to the database. I was wondering how I would be able to write a SQL code using ADO.net for the datagrid so I can update certain things (or I can bind the datagrid but maybe there is a build in edit command) thanks!

Databinding is significantly different in WinForms than it is in ASP.NET. There's no request cycle and databinding is always both ways (controls read data from the datasource and automatically update it as well).
However you'll still need to take the data from your datasource and persist it to the database. How you do that depends on what your datagrid is bound to.
I recommend you review this MSDN article Windows Forms Data Binding and the links that matter to you

Related

MVVM architecture

I need to build our future business applications with WPF using MVVM.
My typical application consists of several windows/tab pages with grids and form style windows. Both edit windows and grid windows can be different depending on the logged in user, so most of them will be built datadriven.
And I'm trying to write as few code as possible, as not written code is the only one to be guaranteed error free .
So, now my question: how to structure the entire thing?
The View is clear to me - is is built using XAML or by code.
The ViewModel should contain the business logic and the validation rules and should let feed the View the data, and should contain the commands for the actions.
So, where to put the data? A select returns a DataTable. Should this datatable exposed through the ViewModel to the View for the grid windows?
And for the form windows? Should the single DataRow exposed trough the ViewModel to the View?
Are there other helper or intermediate classes needed?
Thank you for any useful suggestion!
Wolfgang
Its best way to go with WPF and MVVM,
I suggest before you start go thru the basics of MVVM. for your reference you can understand better here
The preferred UI paradigm in WPF is to have tab controls and grids in a single window, something like this:
You don't have to stop there, you can nest them as deeply as you need to for the sake of clarity.

Filtration for List view data upon List view Header column clicks in WINFORMS

I dont know whether this is possible or not, But i just want your suggestions on this ..
Here is what I would like to be able to do. Not sure if this functionality is built in or if I will need to use a combination of any controls/tools.
I want to be able to filter a listview data.. have it filter the listview accordingly on click of listview columns header.I want to be able to use checkboxes in dropdown of listview header column such that I can filter data easily.
Best Example: Control Panel-->Uninstall a Program ,Where a list of uninstall programs available in listview for computing filtration upon click of any header.
I want this in Windows Forms Applications C# Visual Studio 2010
If solution is possible, pls. share the site links or any free tools also as well.
Here is the same idea for a DataGridView http://www.codeproject.com/Articles/33786/DataGridView-Filter-Popup However, you would have to write the code to do the filtering as a winforms ListView does not supporting binding to a DataTable.
ObjectListView -- an open source wrapper around a .NET ListView -- supports filtering out of the box.

How to View, Edit and Update a Database Table with WPF's DataGrid?

am a newbie in the WPF and more so the WPF Datagrid arena. Am so used to working with the cousin -- DatagridView from Windows Forms, but it's my first time working with WPF's Datagrid Control, and am having a very hard time!
I have created a dataset using the in-built datasource wizard in Vidual Studio 2010. After creating this dataset, I used another in-built feature that allows me to auto-generate a datagrid that is pre-bound to this a table in the dataset, so I can just drop it onto the window.
Now, all that is done nicely, til I come to the part where I need to have the user edit the contents of the datagrid, and via a callback, have the new / updated data committed to the underlying table in the database.
I've tried searching around, but most articles are out-dated, and some don't hit the problem in ways that make sense to a newbie like me.
One source says:
DataGrid checks for
IEditableCollectionView’s CanAddNew,
CanCancelEdit, and CanRemove
properties before executing the
EditItem, CancelEdit, or CommitEdit
methods. So if editing appears to not
work for some reason, be sure to check
that it is able to edit.
from an MSDN source, but the Auto-generation feature of Visual Studio 11 gives me this for the data-binding source
<Window.Resources>
<my:crimexDataSet x:Key="crimexDataSet" />
<CollectionViewSource x:Key="datapoolViewSource" Source="{Binding Path=datapool, Source={StaticResource crimexDataSet}}" />
</Window.Resources>
So, how do I move from this to an IEditableCollectionView kind datasource, so I can have editing enabled? Thanks in advance...
If this isn't an application with a short lifetime, I would save myself a lot of pain and learn about the MVVM (Model-View-ViewModel) pattern. It is a very common pattern in the WPF and Silverlight worlds.
Basically, you would make a class specifically designed to be the data source for the grid, and perhaps other data you would need in your window.
For this particular need, you would probably use an ObservableCollection as the type of the property bound to the grid.
There is a lot of information on MVVM here at StackOverflow, to be found on Google, and in books. If you grok the pattern, it can really make the UI development experience a lot less painful.

WPF Autocomplete Combobox Not Saving To Database VB

Trying to create what i feel should be an easy WPF application. basically what i want it to do is have a autocomplete combobox which is bound to a sql db table. the table has 2 fields(Address and Directions)
once the user selects the record from the address combox the directions textbox below will be filled directions stored in the table.
if there are no records in the address combobox the user can then type in the combobox and add the new entry.
there will be a save button on the form that saves the new entry and will be visible in the list. Im new to WPF applications and have been trying to get this to work for weeks. Any help would be appreciated.
I would start by checking out the following discussion which will point you to several good tutorials on using the MVVM (Model-View-ViewModel) pattern with WPF.
MVVM: Tutorial from start to finish?
Other than that, you haven't really given any indication what you've tried and what isn't working so I can't really offer any other advice. But even the simplest applications in WPF are much cleaner and more easily implemented with MVVM than using code behind and drag and drop data binding.

WPF quick prototyping. See changes without running

I'm doing a WPF application, using Blend4 and VS2010 for editing the XAML files.
One of the most anoying things of this is the process of making small changes and see them in action. As the data in the View is populated from a ViewModel and a Model via Bindings, the things you see in the Blend designer aren't the same you get when you run your application. You need to recompile and "re-run" your application every time you make a change, no matter if it was only to change a pixel in the margin of some element.
I want to know if there is any way to perform quick changes in your XAML and watch them in the real interface.
Like in the Websites, the idea is similar to make a change in the HTML and then press F5 to see the changes.
Maybe you can run "part" of your application to bind the view data to the model, and then change only the "view code" of the xaml.
Do you know if this is possible?
Thanks!
Whether using Blend or Visual Studio, the key to rapid design of MVVM user interfaces is sample data. You can use the same view model at design-time as you you do at run time as long as the data is doesn't access services.
Whether you are using MVVM Light or not, you can use its technique to allow your view-model to detect design time and return different data. You can also read Laurent Bugnion's ideas on sample data here:
WPF: Simulating data in design mode in Microsoft Expression Blend

Resources