473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataGrid class (System.Windows.Forms)

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
Nov 17 '05 #1
5 2057
Hi Sanddevil,

"Sanddevil" <sa*******@amlor.demon.co.uk> schreef in bericht
news:d5*******************@news.demon.co.uk...
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!

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/smartclien...q/default.aspx (main
page)
and in specific
http://msdn.microsoft.com/smartclien...aq/ctrlsp.aspx

Kind regards,
Tom T.
Nov 17 '05 #2

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
schreef in bericht news:p3********************@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
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();

[...]

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

TT
Nov 17 '05 #3
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:47********************@phobos.telenet-ops.be...

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
schreef in bericht news:p3********************@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
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();

[...]

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

TT

Nov 17 '05 #4
Way to go Sanddevil...

TT

"Sanddevil" <sa*******@amlor.demon.co.uk> schreef in bericht
news:d5*******************@news.demon.co.uk...
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:47********************@phobos.telenet-ops.be...

"TT (Tom Tempelaere)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
schreef in bericht news:p3********************@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
> 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();

[...]

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

TT


Nov 17 '05 #5
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:Ap*********************@phobos.telenet-ops.be...
Way to go Sanddevil...

TT

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
0
by: Morné | last post by:
Hi how do I validate a text value in a datagrid e.g. the user is only allowed to type in a Y or a N. I specifically have a problem with using the PropertyDescriptorCollection. I get the...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: Mauro | last post by:
Hi, I need a big help to resolve this problem. I need to put a usercontrol in a datagrid: this control check if the code inserted is present in a archive and if not return a error message. (In...
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
5
by: Genojoe | last post by:
I am using code from Help with two exceptions. (1) I increased the number of sample rows from 3 to 20, and (2) I anchored the datagrid to bottom of form so that I can change the size of the grid by...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.