Datagridview - necessity not to update the data source

G

Guest

Hi,
I have a datagridview to which I bind a collection, something like
TranslateGrid.DataSource = translationCollection.
The grid consists of textboxes.
But when I update the textboxes in the grid, the data in the
collection(translationCollection) is also getting updated which I don't need.
How can this be prevented?
 
B

Bob Powell [MVP]

The whole idea of databinding is to enable the transfer of data from your
model to the user interface.

If the grid is bound to the data you will edit any data automatically.

If you just want to display data without editing you can bind to a list of
objects that wrap your real objects but that have rea-only properties. You
can mark your own properties as read-only using the ReadOnlyAttribute or you
can unbind the data and use a virtual grid mode to display the data without
the underlying databound connection.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
M

Morten Wennevik [C# MVP]

Hi,
I have a datagridview to which I bind a collection, something like
TranslateGrid.DataSource = translationCollection.
The grid consists of textboxes.
But when I update the textboxes in the grid, the data in the
collection(translationCollection) is also getting updated which I don't need.
How can this be prevented?

Hi Vinay,

What should be updated if you update the textbox, if not the underlying datasource?
Do prevent an update of a property of the translationCollection objects,you could create a getter only property, or add a display property thatmay contain a setter which does nothing, or updates something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top