Make dataset ReadOnly?

G

Guest

Is there a simple way to make either an entire dataset or a datatable readonly/not readonly with a single command? (Without setting the readonly property of every textbox or datacolumn to true?)

Thanks,
Denise
 
M

Miha Markic [MVP C#]

Hi Denise,

You might bind to DataView instead of DataTable and set Allow* methods
accordingly.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Denise said:
Is there a simple way to make either an entire dataset or a datatable
readonly/not readonly with a single command? (Without setting the readonly
property of every textbox or datacolumn to true?)
 
G

Guest

Have you tried this solution? I just spent the last 2 hours trying to get this to work, and even when I scaled down to a very simple example, it did not work. I was able to edit the fields even though the dataview's AllowEdit property was false. Am I missing something?
 
M

Miha Markic [MVP C#]

Hi Denise,

This depends on the consumer.
DataGrid supports it, while simple controls apparently not.
I guess you are stuck with setting Enable property to false.
Example:
BindingManagerBase bmb = BindingContext[dataView1];

foreach (Binding b in bmb.Bindings)

b.Control.Enabled = false;


--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Denise said:
Have you tried this solution? I just spent the last 2 hours trying to get
this to work, and even when I scaled down to a very simple example, it did
not work. I was able to edit the fields even though the dataview's
AllowEdit property was false. Am I missing something?
 
C

Cor

Hi Denise,

Is it not more logical to set the controls that the user to "read only" or
something the same.
(If you use "enabled" you do not even have to cast them for most controls
because that is a property from forms.control and you can in the same
routine backgroundcolor)

If you use a loop (and if you have placed controls in other controls a
recursive loop) then it is simple to do.

You can ask how to do that the best (depending the language you are using)
in the newsgroup
public.dotnet.languages.csharp
public.dotnet.languages.vb

I hope this helps?

Cor

"> Is there a simple way to make either an entire dataset or a datatable
readonly/not readonly with a single command? (Without setting the readonly
property of every textbox or datacolumn to true?)
 

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