By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

Problem with DataGridView and BindingSource

P: n/a
Hello,
I have problem with DataGridView and BindingSource. I have created
DataSet and added TableData to it with manualy created columns
(without DataAdapter - I'm not using MSSQL). On the Form I put
DataGridView and BindingSource, and connected them (BindingSource of
course is also connected with DataSet). Next on the separated thread
I'm reading data from DB and load them do DataSet (more preciselly,
readed data I've saved as XML and them this XML load to DataSet).
Everything looks OK - DataSet is filled with rows :D But nothing
appears on the DataGridView, so on the end of thread I've executed
"refreshBS()" method (like below - threadsafe) and the datgridview
fills with rows, too.

public void refreshBS()
{
if (this.InvokeRequired)
{
RefreshUserDetails rud = new
RefreshUserDetails(this.refreshBS);
this.Invoke(rud);
}
else
{
this.DataSet1.AcceptChanges();
this.BindingSource.CurrencyManager.Refresh();
}
}

I thought that everything is OK until I've lunch my application
from .EXE file :-( I have discovered that when I lunch it from .EXE
file it hangs on the line give above
"this.BindingSource.CurrencyManager.Refresh()" (when I lunch this from
Visual Studio (F5) everything works fine).
My question is : is there any other way to refresh DataGridView with
data from BindingSource ?
Also i have tested the method :
CurrencyManager cm = this.Datagridview.bindingcontext.....
cm.refresh()
and the result is the same :-(

Now to refresh data on DataGridView with BindingSource I'm sorting
DataGridView programatically and it helps but I think that it's not
the way it should be done.
Thanks.

Jan 31 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Are you loading your dataset before you set the data source of the
bindingsource to the dataset?

Robin S.
-----------------------------------------
<sh*****@wp.plwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Hello,
I have problem with DataGridView and BindingSource. I have created
DataSet and added TableData to it with manualy created columns
(without DataAdapter - I'm not using MSSQL). On the Form I put
DataGridView and BindingSource, and connected them (BindingSource of
course is also connected with DataSet). Next on the separated thread
I'm reading data from DB and load them do DataSet (more preciselly,
readed data I've saved as XML and them this XML load to DataSet).
Everything looks OK - DataSet is filled with rows :D But nothing
appears on the DataGridView, so on the end of thread I've executed
"refreshBS()" method (like below - threadsafe) and the datgridview
fills with rows, too.

public void refreshBS()
{
if (this.InvokeRequired)
{
RefreshUserDetails rud = new
RefreshUserDetails(this.refreshBS);
this.Invoke(rud);
}
else
{
this.DataSet1.AcceptChanges();
this.BindingSource.CurrencyManager.Refresh();
}
}

I thought that everything is OK until I've lunch my application
from .EXE file :-( I have discovered that when I lunch it from .EXE
file it hangs on the line give above
"this.BindingSource.CurrencyManager.Refresh()" (when I lunch this from
Visual Studio (F5) everything works fine).
My question is : is there any other way to refresh DataGridView with
data from BindingSource ?
Also i have tested the method :
CurrencyManager cm = this.Datagridview.bindingcontext.....
cm.refresh()
and the result is the same :-(

Now to refresh data on DataGridView with BindingSource I'm sorting
DataGridView programatically and it helps but I think that it's not
the way it should be done.
Thanks.

Feb 1 '07 #2

P: n/a
On 1 Lut, 10:49, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Are you loading your dataset before you set the data source of the
bindingsource to the dataset?

Robin S.
No. All connections between DataSet, BindingSource and DataGridView
are done at the design level, from the Visual Studio. DataSet is
filling with data after launching the application (thread). It's
needed because I want to format columns in DataGridView at the design
level.

Feb 1 '07 #3

P: n/a
Also I want to mention that this problem occurs only if there will be
more rows than DataGridView can show at one time. For example if
DataGridView can fit only 10 rows (on the screen) and I want to show
12 rows the application will hang, but if I want to show only 8 rows
then everything will be OK.
Feb 1 '07 #4

P: n/a
Yeahhhhhh..... ;-)
I have discovered that the problem occurs only if there are visible
Scrollbars in the GridView !!! If I disable scrollbars, load data to
DataSet, then shows it in the datagridview and enabled scrollbars at
the end, everything works OK ! If I use this trick there is no more
problem with CurrencyManager.Refresh() :D
C# MVP check it and eventually correct it (ServicePack 1 for VS 2005
dosen't help). I think that it is a bug in C#.

Feb 2 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.