473,474 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Disabling Rows in DataGridView

Hi,
I am new to the forms world and have a silly doubt.

I have form with a DataGridview and an "Add" button. When the user
clicks on the add button, one row gets added to the datagrid.
Now I want that when the user hits the "Add" button, then new row
should be added and all the previous rows should be disabled for
selection/editing.

How can I disable previous rows for selection/editing?

Here is my sample code (just example..won't compile)

private void buttonAdd_Click(object sender, EventArgs e)
{
// Add new row
DataRow row;
row = diagnosticsTable.NewRow();
// Then add the new row to the collection.
row["DIAGNOSTIC_NAME"] = "AddDiagnosticsName";
row["DIAGNOSTIC_DESCRIPTION"] =
"AddDiagnosticsDescription";
row["SYSTEM_NAME"] = "Newsys";
diagnosticsTable.Rows.Add(row);

this.dataGridViewDiagnostic.CurrentCell =
this.dataGridViewDiagnostic[1, 0];
}

Thankyou...

Oct 20 '06 #1
2 12560
MMA
Get the Collection of DataGridViewRows.

Then go through all rows and set the ReadOnly property to true.

following which you can add the new row

"sh********@gmail.com" wrote:
Hi,
I am new to the forms world and have a silly doubt.

I have form with a DataGridview and an "Add" button. When the user
clicks on the add button, one row gets added to the datagrid.
Now I want that when the user hits the "Add" button, then new row
should be added and all the previous rows should be disabled for
selection/editing.

How can I disable previous rows for selection/editing?

Here is my sample code (just example..won't compile)

private void buttonAdd_Click(object sender, EventArgs e)
{
// Add new row
DataRow row;
row = diagnosticsTable.NewRow();
// Then add the new row to the collection.
row["DIAGNOSTIC_NAME"] = "AddDiagnosticsName";
row["DIAGNOSTIC_DESCRIPTION"] =
"AddDiagnosticsDescription";
row["SYSTEM_NAME"] = "Newsys";
diagnosticsTable.Rows.Add(row);

this.dataGridViewDiagnostic.CurrentCell =
this.dataGridViewDiagnostic[1, 0];
}

Thankyou...

Oct 20 '06 #2

Thanks for your response.
Actually what I want is all the rows except the newly added row should
be greyed out.
Also, due you suggest any good tutorial/ sample on this?

MMA wrote:
Get the Collection of DataGridViewRows.

Then go through all rows and set the ReadOnly property to true.

following which you can add the new row

"sh********@gmail.com" wrote:
Hi,
I am new to the forms world and have a silly doubt.

I have form with a DataGridview and an "Add" button. When the user
clicks on the add button, one row gets added to the datagrid.
Now I want that when the user hits the "Add" button, then new row
should be added and all the previous rows should be disabled for
selection/editing.

How can I disable previous rows for selection/editing?

Here is my sample code (just example..won't compile)

private void buttonAdd_Click(object sender, EventArgs e)
{
// Add new row
DataRow row;
row = diagnosticsTable.NewRow();
// Then add the new row to the collection.
row["DIAGNOSTIC_NAME"] = "AddDiagnosticsName";
row["DIAGNOSTIC_DESCRIPTION"] =
"AddDiagnosticsDescription";
row["SYSTEM_NAME"] = "Newsys";
diagnosticsTable.Rows.Add(row);

this.dataGridViewDiagnostic.CurrentCell =
this.dataGridViewDiagnostic[1, 0];
}

Thankyou...
Oct 20 '06 #3

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

Similar topics

10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
3
by: steve | last post by:
Hi All How can I get the datagridview to redraw after changing the rowtemplate.height at runtime ( it is databound to a datatable) I have tried datagridview1.refresh etc to no avail (The row...
1
by: jjmurali | last post by:
hi guys i have one problem with datagridview.. i m displaying data in datagridview in c# application. i added one checkbox column to datagridview ..as well as i have one button(Select All),...
1
by: Karl | last post by:
Hi all... This is a good one. You'll like this... I am working on a course management tool that allows certain Courses to be cross referenced with Job Roles and, when they are, whether the...
1
by: gaya3 | last post by:
How do i disable particular row in JTable? -Thanks & Regards, Hamsa
6
by: akshaycjoshi | last post by:
I have one datagridview which i fill using the connected verion of ADO.NET. When the user presses the search button a seperate thread is created and in that thead i connect to the database and fill...
2
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.