Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2004, 01:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Windows DataGrid question

When loading a windows datagrid in my windows form I am only binding the datasource to the datagrid:

//bind the DataSet to the Windows data grid
dataGrid1.DataSource = il.InvoiceData;

However, my question is: it would appear that by default the datagrid loads with the opportunity for a user to ADD a new record. I DO NOT WANT TO SHOW a NEW ROW. How can I eliminate this row? FYI--I cannot make this a readonly datagrid because one of my columns is a checkbox whereby they can delete the record but I do not want the user to add and/or edit from this datagrid, if that makes sense.

Any help would be appreciated. Thank you.
 
Old July 22nd, 2004, 02:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

I got this bolded code from a colleague however I am getting an error when I put this code after I've binded the dataset to the Windows datagrid:

//bind the DataSet to the Windows data grid
dataGrid1.DataSource = il.InvoiceData;
this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
((DataView)il.List).AllowNew = false;

Any suggestions? The errors that I am getting are:

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

'InvoiceManager.InvoiceList' does not contain a definition for 'List'
 
Old July 22nd, 2004, 02:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use a DataView to disable AddNew. Drag a DataView component on your form. Bind your data to it's Table property. Then set AllowNew to false:

dataView1.AllowNew

Finally, bind the DataView to your Grid:

dataGrid1.DataSource = dataView1;


Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Temptation by New Order (Track 3 from the album: Substance - Disc 1) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to freeze the columns in windows DataGrid? pradpb999 ADO.NET 0 July 31st, 2006 06:19 AM
windows forms datagrid - refresh ab_dev General .NET 0 March 1st, 2006 06:37 PM
Windows Data Grid question savoym C# 1 May 12th, 2004 12:04 AM
DataGrid(Windows Form) shiju VS.NET 2002/2003 1 November 1st, 2003 11:55 PM
Windows Forms DataGrid .NET antalpak VS.NET 2002/2003 2 June 20th, 2003 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.