.NETGURU
How to disable 'new row' in DataGrid?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.academic.

Post a new message to this list...

Allan Wong
Is there a way to disable new rows in DataGrid?

There is a a * (asterisk) always at the last row of the datagrid.
The datagrid contains editable data and I do not want to use "ReadOnly=True"
to disable the "New Row (*)" at the end of the datagrid.

Any information is appreciated. Thanks.

Regards,
Allan

Reply to this message...
 
    
Allan Wong
Found a solution.

There is 10 rows in my Data Grid.
When user tries to go to new row (the asterisk row), 11th row, re-position
the cell to the last row (10th row).

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles DataGrid1.CurrentCellChanged

If (DataGrid1.CurrentCell.RowNumber > 10) Then
DataGrid1.CurrentCell = New DataGridCell(10,
DataGrid1.CurrentCell.ColumnNumber) ' Re-position back to 10th row
End If

End Sub

"Allan Wong" <Click here to reveal e-mail address> wrote in message
news:ODKQ3QG3BHA.1940@tkmsftngp05...
[Original message clipped]

Reply to this message...
 
    
Arun Srinivasan
Hi Allan,

Take a look at the following FAQ from George Shepherds's Windows Forms FAQ:

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q653q

which has been reproduced below:

5.5 How do I prevent the datagrid from displaying its append row (the row at
the end with an asterisk)?

The DataGrid class does not have a property that controls whether a new row
can be added. But the DataView class does have such a property (along with
some others such as AllowEdit and AllowDelete). Here is code that will turn
off the append row.

string connString = @"Provider=Microsoft.JET.OLEDB.4.0;data
source=C:\northwind.mdb";

string sqlString = "SELECT * FROM customers";
// Connection object
OleDbConnection connection = new OleDbConnection(connString);
// Create data adapter object
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sqlString,
connection);

// Create a dataset object and fill with data using data adapter's Fill
method
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "customers");
// Attach dataset's DefaultView to the datagrid control
dataGrid1.DataSource = dataSet.Tables["customers"].DefaultView;
// do not allow an appendrow...
((DataView)dataGrid1.DataSource).AllowNew = false;

Regards,

Arun Srinivasan
Syncfusion Inc
http://www.syncfusion.com
..NET Essentials

"Allan Wong" <Click here to reveal e-mail address> wrote in message
news:#oLssiG3BHA.2592@tkmsftngp04...
[Original message clipped]

Reply to this message...
 
    
Benjamin Peikes
Actually the way to do it is to make it ReadOnly. Then the
last line disappears.

[Original message clipped]

Reply to this message...
 
    
Allan Wong
I actually need the DataGrid to be in Editing mode. So cannot use ReadOnly.
Sorry for missing out in the last message.

"Benjamin Peikes" <Click here to reveal e-mail address> wrote in message
news:362201c1dcd0$85ddf9f0$39ef2ecf@TKMSFTNGXA08...
[Original message clipped]

Reply to this message...
 
    
Allan Wong
Solution :-

myDataTable = myDataSet.Tables.Item("TestTable")
myDataRow = myDataTable.NewRow()
myDataRow("Quantity") = "9"
myDataRow("UnitPrice") = "9.9"

'Insert new row at Row 3
myDataTable.Rows.InsertAt(myDataRow, 2)
myDataTable.AcceptChanges()

The solution is from below :-

From: Ryan Trudelle-Schwarz
Date Posted: 4/6/2002 11:53:00 PM

This seems to be a popular question lately.

The problem is that the datatable is holding the new element at the end
until you accept the changes on the table. Once accepted, the datagrid will
put it in the proper location.

So, doing a myDataTable.AcceptChanges() will allow the datagrid to sort as
you want.

Alternatively, if you want them sorted, you can bind to a view and set the
sort.

"Allan Wong" <Click here to reveal e-mail address> wrote
> I have a DataGrid (unbound data) with 5 rows. How can I insert a row at
Row
[Original message clipped]

Reply to this message...
 
    
Sameers (theAngrycodeR)
Its more than simple to disable adding new row in datagrid. I used a Table to populate the grid and was needed to disable new row so I wrote.

mTable.DefaultView.AllowNew = False

That's all.

BTW, you can also check

Ctype(DataGrid.DataSource, DataTable).DefaultView.AllowNew = False

--------------------------------
From: Sameers (theAngrycodeR)
http://www.theangrycoder.com
Reply to this message...
 
    
dan williams
(Type your message here)

--------------------------------
From: dan williams

Protected Overridable Sub OnRowChanged(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles moTBLPortfolio.RowChanged
Dim i As Integer
If e.Action = DataRowAction.Add Then
e.Row.RejectChanges()
End If
End Sub
Reply to this message...
 
 
System.Data.DataRowAction
System.Data.DataRowChangeEventArgs
System.Data.DataSet
System.Data.DataTable
System.Data.DataView
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbDataAdapter
System.EventArgs
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.DataGrid
System.Windows.Forms.DataGridCell




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification