Solved

Refreshing DataGridView Control

Posted on 2008-06-10
6
811 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
Comment Utility
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
Comment Utility
No DataBind() property in windows form
0
 
LVL 16

Expert Comment

by:ororiole
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:smaguire
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now