Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Refreshing DataGridView Control

Posted on 2008-06-10
6
Medium Priority
?
828 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
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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