Solved

Refreshing DataGridView Control

Posted on 2008-06-10
6
818 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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