index > Visual Studio Tools for Office > List Object in excel - how to stop user deleting rows

List Object in excel - how to stop user deleting rows


how can i stop the user deleting rows from a data bound list object.

There is no setter on the AllowDelete property of the BindingSource object, detecting when a row is deleted on the underlying dataset and rejecting the changes stops the row from being deleted from the dataset but it leaves an empty list row in the list.

rebinding the BindingSource to the dataset has no effect either
Michael Pritchard

A DataTable does not allow this setting. To achieve this, you need to change the way you are data binding the table to the ListObject.

Instead of specifying the DataTable as the DataSource for the BindingSource, you need to create a DataView object over the DataTable. A DataView allows setting the AllowDelete property and you can set this to false. Then specify this DataView as the DataSource for the BindingSource.

Thanks.




This posting is provided "AS IS" with no warranties, and confers no rights.
Mohit Gupta - MSFT
Ok, so I create my DataView by doing:

DataView dv = new DataView(ds.Table);
dv.AllowDelete = false;
Globals.WorkSheet.tableBindingDataSource.DataSource = dv;

I have also set on the worksheet class:
tableBindingDataSource.DataSource = typeof(DataView); - this was previsouly a typed dataset

The user can still delete rows from the list object.

Using a dataview also removes the constraints on the user being to delete/edit Read Only columns in the typed DataSet

I've also tried:

ds.Table.DefaultView.AllowDelete = false;
Globals.WorkSheet.tableBindingDataSource.DataSource = ds.Table.DefaultView;

and the user can still delete rows and the read-only column constraints are still broke;
Michael Pritchard
seen as no-one can shed any more light on to this I have made minor workaround that disables the right click on the list object, although the user can still add the list object toolbar and delete a row that way.

Anyway, my typed dataset contraints are back working, i.e. some cells are read-only, however - if the user selects the entire row by clicking the row number (e.g. 5) and presses delete, all the data in the list is seemingly deleted - if you however go into the read only cell and press delete, the old value is returned.
Michael Pritchard
reply 4

You can use google to search for other answers

 

More Articles

Demonstration at VSLive Orlando
Add/Remove Worksheet in VSTO Workbook
Problems executing code in Word projects
Binding Pictures/Images in Word Documents
Why VSTO?
How to export data to Excel file effectively
Access ICal UID from VSTO
Something Missing with Intellisense due to VSTO install
create a new worksheet in a excel file using VBA
Event for text change
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Word 2007 customized ribbon deployment
VSTO August CTP COM Exception
Print to upper tray in Access
Add menu button in multi-lingual environ…
need help related to VSTO 2005
Shared Add-in - Excel Add-in for Office …
Repeating data in Word - how to?
Drawing XY Scatter Graph With OWC11
Mouse hover event over a range of cells …
Auto Sum From Left to Right
Select worksheet explicitly
Multilingual CommandBar?
Binding a 2D array to a ListObject contr…
IDE VSNET2005 VSTO2 Crash: Help me pleas…
MS Access opening exclusivly

Hot Articles

VSTO seminars
Do userproperties exist on a email folder?
How to install VSTO on VS2005 Profession…
Difficult to Layout InfoPath Forms
VSTO 2005 Won't Install on Vista build 5…
adding a button to the email message win…
InfoPath 2007 Dynamic DataBinding
save a document without the action pane
Customizing Outlook 2007 Ribbon -- idMso…
Excel Application Object question
MSFlexGrid init fails only on some boxes…
PPT SlidShow by Form
Excel errors
Setting image on a CommandBarButton in M…
.net application with an excel interface

Recommend Articles

Using InsertXML method?
Retrieve cell contents and calculations …
Creating word template with bookmarks. i…
Why does CustomTaskPane.Window return an…
Save worddocument
Creating Excel Report file From VB.Net 2…
Will Intellisense show all members even …
Action Pane disappears
ListObject binding
How to display progress on Excel Status …
Thank you & Merry Christmas (free ga…
rtf/wmf question
C++ AddIns 4 MS-Word
How to find start and end data cell?
Synching Palm with MS Outlook