Click here to Skip to main content
15,610,517 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello Team,

I am migrating from Windows Form Application to Windows Presentation Foundation(WPF)
But I am facing few issues -
Please Help -
1. Where is "BindingSource" in WPF as we have in WinForm App
2. Is There any alternative code to solve my problem (
Populate & Add/Edit/Delete Records from WPF DataGrid 

I have below WinApp Code to Populate & Add/Edit/Delete Records from DataGridView.
I want to do the same in WPF - Pleseeeee help -

OleDbConnection Con_Admin = new OleDbConnection();
BindingSource bs = new BindingSource();
OleDbDataAdapter da;
DataTable dt;
		public void Show_GridView()
            dataGridView1.DataSource = null;            
            da = new OleDbDataAdapter(MyQry, Con_Admin);
            OleDbCommandBuilder MyCommandBuilder = null;
            MyCommandBuilder = new OleDbCommandBuilder(da);
            dt = new DataTable();
            bs.DataSource = dt;
            dataGridView1.DataSource = bs;            
        public void SaveChanges()
            catch (Exception exceptionObj)
Updated 14-Aug-21 12:27pm

I think you're looking for DataContext.

Share this answer
Pravinkarne.31 2-Oct-13 7:27am    
No I am not looking for DataContext.
In my above code you can see that - I am using
BindingSource bs = new BindingSource();
and then
bs.DataSource = dt;
dataGridView1.DataSource = bs;

Which is allow me to make any changes in DataGridView and same will be automatically(da.Update()) gets updated in DataBase.
Hence I am searching for BindingSource in WPF OR any alternative to it
Please Help -
Fredrik Bornander 2-Oct-13 7:34am    
I think you should set the DataContext to your DataTable and ignore the BindingSource. Why do you need the BindingSource?
Pravinkarne.31 2-Oct-13 7:51am    
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;
WHICH Help me - to make any changes in DataGridView and same will be automatically(da.Update()) gets updated in DataBase.
Hence I am searching for BindingSource in WPF OR any alternative to it
Irina Pykhova 2-Oct-13 8:18am    
I see, you just don't want to read something, you wan't to get winforms code, replace one thing and get it working. You need a powerful magic. Sorry, I don't have one
Fredrik Bornander 3-Oct-13 3:02am    
look at this article: WPF DataGrid Practical Examples
Share this answer
Pravinkarne.31 2-Oct-13 7:34am    
Sorry No Use!!
Allready downloaded and checked but of no use...
I think you all are not getting my question correctly...
Please Help!!!
Irina Pykhova 2-Oct-13 7:43am    
to get someone to get your question correctly, you should ask more specific questions. Why can't you use this article? What exactly doesn't work for you? I suppose, attached code might be outdated as the article is quite old, but all ideas still true. It shows how to bind your data to DataGrid and how to save updates. I thought that it is exactly what you are looking for.
Hi , u can just Replace :

BindingSource source = new BindingSource();
source.DataSource = cmd.ExecuteReader();
dataGridView1.DataSource = source;

By :

DataGridView1.ItemsSource = cmd.ExecuteReader().Cast<dbdatarecord>().ToList();
Share this answer
CHill60 16-Aug-21 6:09am    
OP cannot replace that code as it is not in their original code. And quite frankly I find the 3 lines of code easier to follow than that mangled one-liner

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900