Solved

Refreshing DataGridView Control

Posted on 2008-06-10
6
819 Views
Last Modified: 2013-12-17
hi all,
I have a DataGridView Control that is bound to a dataset and the ds linked to a stored procedure
the DGV is placed in a tab control, whenever the user clicks that tab, I call the following method:
private void InitializeDisplaySettingsGrid()
        {
            dgvDisplaySettings.DataSource = null;
            dgvDisplaySettings.DataSource = ds.CustomDisplaySettings.DefaultView;
        }
it works and show data just fine, but if I change anything in the table (from the database or from the application) the new modified data will not show until the I stop and restart the application.
I tried to use dgvDisplaySettings.Refresh() but didn't help, I also tried manually as you can see from the code above to set the datasource to null and then call it again, without any luck

Why can't I get it to show the modified data IF i am binding it to the datasource everytime the user selects that tab page?
I am using windows forms, and visual studio 2008

thanks
0
Comment
Question by:smaguire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 21753870
use
dgvDisplaySettings.DataSource = ds.CustomDisplaySettings.DefaultView;
dgvDisplaySettings.DataBind();

Binding doesnt actually occur until the DataBind event, which you can ensure by calling DataBind() anytime your datasource changes. If your database table changes, you are going to need to go get it again and update your datatable. (At least, thats the basic way)
0
 

Author Comment

by:smaguire
ID: 21753890
No DataBind() property in windows form
0
 
LVL 16

Expert Comment

by:ororiole
ID: 21754182
Ah. In that case call Refresh in the DataBindingComplete event
        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
           dataGridView1.Refresh();
        }

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:smaguire
ID: 21754253
Thanks ororiole for your reply,
I've tried that and still does not work. I can verify data being changed in the database but will not show in the grid until i restart the app

thanks
0
 
LVL 16

Expert Comment

by:ororiole
ID: 21755142
SEt a breakpoint in the DAtaBindComplete event handler to make sure it is bering raised. Then take a look at the DataBindingCompelteEventArgs to see if the CompleteState is Success and/or what ErrorText may be.

Make sure you are reloading your dataset/datatable when the database changes.
0
 

Accepted Solution

by:
smaguire earned 0 total points
ID: 21759283
thanks ororiole for your reply,

This is how I got it working:
1- Create a DataTable
2- Fill the DataTable
3- Set the DataGridView. DataSource = DataTable

And I am doing this EVERYTIME, I need to refresh the grid, it's not ideal but it works for now.
I will give u partial points for trying to help me out
thanks
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question