Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

DataGrid class (System.Windows.Forms)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sanddevil - 30 Apr 2005 19:19 GMT
Hi there - I hope someone out there can help me! I'm using a .Net DataGrid
Class to show the results of a SQL query in a spreadsheet type control. The
code, which works fine is:

iRowCount = oleDbDataAdapter1->Fill(dataSet1);

dataGrid1->DataSource = dataSet1->Tables->Item[0]->DefaultView;

I then update the underlying data in the database elsewhere in the code by
adding
some new rows and
want the datagrid control to show the updated and new rows correctly. I do a
refresh
to ensure the dataSet is up-to-date with the following statement:

iRowCount = oleDbDataAdapter1->Fill(dataSet1);

and having checked the iRowCount value I know that the dataSet has
definitely got the new rows.

So, the question is, how do I get the DataGrid to show the updated data on
the screen? There doesn't appear to be a Reload / Rebind type method in the
System.Windows.Forms.DataGrid Class. The Refresh() method doesn't do it. Any
help will be most appreciated!

Cheers
TT \(Tom Tempelaere\) - 01 May 2005 10:11 GMT
Hi Sanddevil,

> Hi there - I hope someone out there can help me! I'm using a .Net DataGrid
> Class to show the results of a SQL query in a spreadsheet type control.
[quoted text clipped - 24 lines]
> Any
> help will be most appreciated!

Although I'm not sure, I think "Invalidate" method could do that. What I
also think is that there is probably still a better way, but I never did
what you do. Invalidate actually forces the control to repaint itself.

Another thing I haven't tested but that might work, is to use the
SuspendBinding and ResumeBinding methods of the BindingManager of your grid.
Call SuspendBinding before modifying the DataSet and ResumeBinding after
that. You can retrieve the BindingManager using the BindingContext property
of your DataGrid:

   BindingManagerBase bm;
   bm = dataGrid.BindingContext[ dataGrid.DataSource,
dataGrid.DataMember ];
   bm.SuspendBinding();
   // update data
   bm.ResumeBinding();

An interesting FAQ that might help you further is
   http://msdn.microsoft.com/smartclient/community/wffaq/default.aspx (main
page)
and in specific
   http://msdn.microsoft.com/smartclient/community/wffaq/ctrlsp.aspx

Kind regards,
Tom T.
TT \(Tom Tempelaere\) - 01 May 2005 10:15 GMT
"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
schreef in bericht news:p31de.78253$mZ.5067907@phobos.telenet-ops.be...
[...]
> Another thing I haven't tested but that might work, is to use the
> SuspendBinding and ResumeBinding methods of the BindingManager of your
[quoted text clipped - 8 lines]
>    // update data
>    bm.ResumeBinding();
[...]

This example uses C#, just to mention... But it should be similar in MC++

TT
Sanddevil - 01 May 2005 11:37 GMT
Hi Tom - many thanks for taking the trouble to respond to me. It was much
appreciated, and your suggestion worked!

The syntax was a little tricky in C++, so for the benfit of anyone stumbling
upon this in the future:

BindingManagerBase* pBm;

pBm = dataGrid1->BindingContext->Item[dataGrid1->DataSource,
dataGrid1->DataMember];

pBm->SuspendBinding();

// Do your updates to the underlying database here

pBm->ResumeBinding();

Many thanks again.
Cheers
Sanddevil

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
wrote in message news:471de.78259$G6.5045284@phobos.telenet-ops.be...

> "TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
> schreef in bericht news:p31de.78253$mZ.5067907@phobos.telenet-ops.be...
[quoted text clipped - 16 lines]
>
> TT
TT \(Tom Tempelaere\) - 01 May 2005 15:08 GMT
Way to go Sanddevil...

TT

> Hi Tom - many thanks for taking the trouble to respond to me. It was much
> appreciated, and your suggestion worked!
[quoted text clipped - 43 lines]
>>
>> TT
Sanddevil - 02 May 2005 10:21 GMT
In fact, I've come across another solution which I'll preserve here for
prosterity in case others need it.

This solution involves clearing the dataset and then reloading it. No
performance issues either - on my creaky old laptop it is a blink of an eye.

// Load the grid

iRowCount = oleDbDataAdapter1->Fill(dataSet1);

dataGrid1->DataSource = dataSet1->Tables->Item[0]->DefaultView;

// add / amend rows in the underlying database elsewhere in the code

// update the screen
dataSet1->Clear();

iRowCount = oleDbDataAdapter1->Fill(dataSet1);

Cheers

Sanddevil

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
wrote in message news:Ap5de.78480$vm1.5084170@phobos.telenet-ops.be...
> Way to go Sanddevil...
>
> TT

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.