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

Disable editing on a row basis on DataGrid (winforms)

P: n/a
I have a datagrid that I want to be able to allow me to edit only the first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you
Jun 5 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I forgot to say I use VB.NET 2003

"Gentian Hila" wrote:
I have a datagrid that I want to be able to allow me to edit only the first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you
Jun 5 '07 #2

P: n/a
Gentian,

AFAIK impossible, the datagrid was greath but in fact very poor in use,
therefore came the datagridview

Cor

"Gentian Hila" <Ge*********@discussions.microsoft.comschreef in bericht
news:23**********************************@microsof t.com...
>I forgot to say I use VB.NET 2003

"Gentian Hila" wrote:
>I have a datagrid that I want to be able to allow me to edit only the
first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you

Jun 5 '07 #3

P: n/a
Thanks. But that is only for Visual Studio 2005 right? I am using 2003 and it
may take a while before I do that transition.

In the meantime what can I do with 2003?

"Cor Ligthert [MVP]" wrote:
Gentian,

AFAIK impossible, the datagrid was greath but in fact very poor in use,
therefore came the datagridview

Cor

"Gentian Hila" <Ge*********@discussions.microsoft.comschreef in bericht
news:23**********************************@microsof t.com...
I forgot to say I use VB.NET 2003

"Gentian Hila" wrote:
I have a datagrid that I want to be able to allow me to edit only the
first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you


Jun 5 '07 #4

P: n/a
Gentian Hila wrote:
I have a datagrid that I want to be able to allow me to edit only the
first two rows and all the other rows to be read-only.
Assuming the DataGrid in VS2003 works the same as in VS2005 (I don't know
whether it does or not, I only have VS2005 installed), you should be able to
achieve this by:

- declaring a class that inherits from Windows.Forms.DataGridTextBoxColumn

- in the class, override the Edit method. Add code that calls into the base
class if the rowNum is one you want to be editable, or simply returns
without doing anything if you want the column to be read-only.

- when initialising the grid, create a new Windows.Forms.DataGridTableStyle
object.

- for each column in the grid, add a new instance of your class from above
to the DataGridTableStyle object. Make sure you set the MappingName property
of the object to match the underlying column name in your DataTable, and
also set the HeaderText, Width, Alignment and anything else you need.

- once you've added all your columns, add the DataGridTableStyle object to
the DataGrid.TableStyles collection.

- finally, set the DataGrid's DataSource.

Hopefully that will do what you want!

--

(O)enone
Jun 5 '07 #5

P: n/a
Maybe you can set two datagrids above each other. However the problem stays
that read only and things like that with a datagrid in 2003 is done with the
dataview.

Cor

"Gentian Hila" <Ge*********@discussions.microsoft.comschreef in bericht
news:D5**********************************@microsof t.com...
Thanks. But that is only for Visual Studio 2005 right? I am using 2003 and
it
may take a while before I do that transition.

In the meantime what can I do with 2003?

"Cor Ligthert [MVP]" wrote:
>Gentian,

AFAIK impossible, the datagrid was greath but in fact very poor in use,
therefore came the datagridview

Cor

"Gentian Hila" <Ge*********@discussions.microsoft.comschreef in bericht
news:23**********************************@microso ft.com...
>I forgot to say I use VB.NET 2003

"Gentian Hila" wrote:

I have a datagrid that I want to be able to allow me to edit only the
first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you



Jun 6 '07 #6

P: n/a
Hi:

If I recall correctly, the 2003 DataGrid was originally designed by
componentone, and should have a rowcolchange event, row property, and
AllowUpdate property?

If so, then you check which row you are in in the rowcolchange event, then
set the allowupdate property accorindingly.

hope this helps,
--
Doug.

"Gentian Hila" wrote:
I forgot to say I use VB.NET 2003

"Gentian Hila" wrote:
I have a datagrid that I want to be able to allow me to edit only the first
two rows and all the other rows to be read-only.

How can I do that? Any insight is highly appreciated.

I have spent couple of days on research but no luck so far.

Thank you
Aug 4 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.