Datagrid - Prevent Delete / New Rows 
Author Message
 Datagrid - Prevent Delete / New Rows

How to I prevent it from displaying last blank row?  and how do prevent row
deletes?    I can't set to read only because users need to be able to edit
data.


Tue, 14 Sep 2004 07:12:59 GMT  
 Datagrid - Prevent Delete / New Rows
My good friend, the ADO.NET guru, Andy Baron, suggested this solution
when I asked him about this:

"Maybe you got the answer by now, but I think it is to bind to a
DataView and to set the AllowDelete and AllowNew properties of the
dataview to false."

I rigged up a test case, using a SqlDataAdapter pulling "SELECT * FROM
Customers", and wrote this code:

    Dim dv As New DataView()
    Dim ds As New DataSet()

    SqlDataAdapter1.Fill(ds)
    dv = ds.Tables(0).DefaultView
    dv.AllowDelete = False
    dv.AllowNew = False
    DataGrid1.DataSource = dv

Worked great! Hopefully, that meets your needs.

On Thu, 28 Mar 2002 17:12:59 -0600, "Chris Cairns"

Quote:

>How to I prevent it from displaying last blank row?  and how do prevent row
>deletes?    I can't set to read only because users need to be able to edit
>data.

-- Ken
MCW Technologies
http://www.mcwtech.com


Wed, 15 Sep 2004 06:07:19 GMT  
 Datagrid - Prevent Delete / New Rows
Thanks Ken!   btw I found your books helpful also.



Quote:
> My good friend, the ADO.NET guru, Andy Baron, suggested this solution
> when I asked him about this:

> "Maybe you got the answer by now, but I think it is to bind to a
> DataView and to set the AllowDelete and AllowNew properties of the
> dataview to false."

> I rigged up a test case, using a SqlDataAdapter pulling "SELECT * FROM
> Customers", and wrote this code:

>     Dim dv As New DataView()
>     Dim ds As New DataSet()

>     SqlDataAdapter1.Fill(ds)
>     dv = ds.Tables(0).DefaultView
>     dv.AllowDelete = False
>     dv.AllowNew = False
>     DataGrid1.DataSource = dv

> Worked great! Hopefully, that meets your needs.

> On Thu, 28 Mar 2002 17:12:59 -0600, "Chris Cairns"

> >How to I prevent it from displaying last blank row?  and how do prevent
row
> >deletes?    I can't set to read only because users need to be able to
edit
> >data.

> -- Ken
> MCW Technologies
> http://www.mcwtech.com



Wed, 15 Sep 2004 07:36:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to prevent adding new rows to a datagrid

2. Preventing DataGrid Row/Column Resizing At Runtime

3. How to delete a row in a datagrid.

4. Delete a row in a Datagrid using VB.net

5. DataGrid row delete

6. How to delete row from datagrid

7. Datagrids, DataSets and deleting Rows

8. DataGrid: how to handle deleted rows

9. Delete a row from datagrid

10. Disable Delete row function in Datagrid

11. Delete Row in Datagrid

12. DELETE all rows in datagrid

 

 
Powered by phpBB® Forum Software