Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Stoping the deletion of record on a datagrid

Posted on 2004-11-12
8
Medium Priority
?
173 Views
Last Modified: 2010-04-24
Hi
i hav a form with a datagrid object, which shows  the data correctly, but when we click delete on the the datagrid window it delets the current record, i want to know a way i can stop this.
 and  also is it possible to change the font style for a particular column on a datagrid

thanks
0
Comment
Question by:gajender_99
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:james-ct16
ID: 12564985
Hi
there is a simple sollution to locking out deletion, if you bind a data view to it eg defaultview you can set the property to allowdelete=false. this should solve your first problem the second incolves setting table styles which is a little trickier.

there is a good guide here

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/wnf_CustDataGrid.asp

hope that helps

james
0
 
LVL 8

Author Comment

by:gajender_99
ID: 12565193
hi hames can you provide the systax for locking on deletion as i am a new to .net
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12565305
hi
sorry i usually give little code snippets dont know why i didnt for this.

'load data
        dim dt as datatable

'fill the datatable

'now lock down the dataview
        dt.DefaultView.AllowDelete = False
        dt.DefaultView.AllowNew = False
        dt.DefaultView.AllowEdit = False
'now apply the dataview to the datagrid
        Me.[datagrid].DataSource = dt.DefaultView

hope that is of assistance

james
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:gajender_99
ID: 12566267
hi james

i have datagrid and this was generated using the default form data wizard and now i am having problems , i am not able to do what you have suggested

can you help me out of this
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12566342
hi

can you post the code you have to fill the datagrid, ie the dataset or datatable and the name of the datagrid and i shall have a look at it. have to confess to never using the wizard always do it by hand.

james
0
 
LVL 8

Author Comment

by:gajender_99
ID: 12566408
grdBENEFICIARY is datagrid

Public Sub LoadDataSet()
        'Create a new dataset to hold the records returned from the call to FillDataSet.
        'A temporary dataset is used because filling the existing dataset would
        'require the databindings to be rebound.
        Dim objDataSetTemp As child_carepass.new_order
        objDataSetTemp = New child_carepass.new_order
        Try
            'Attempt to fill the temporary dataset.
            Me.FillDataSet(objDataSetTemp)
        Catch eFillDataSet As System.Exception
            'Add your error handling code here.
            Throw eFillDataSet
        End Try
        Try
            grdBENEFICIARY.DataSource = Nothing
            'Empty the old records from the dataset.
            objnew_order.Clear()
            'Merge the records into the main dataset.
            objnew_order.Merge(objDataSetTemp)
            grdBENEFICIARY.SetDataBinding(objnew_order, "BENEFICIARY")
        Catch eLoadMerge As System.Exception
            'Add your error handling code here.
            Throw eLoadMerge
        End Try

    End Sub


Public Sub FillDataSet(ByVal dataSet As child_carepass.new_order)
        'Turn off constraint checking before the dataset is filled.
        'This allows the adapters to fill the dataset without concern
        'for dependencies between the tables.
        dataSet.EnforceConstraints = False
        Try
            'Open the connection.
            Me.OleDbConnection1.Open()
            'Attempt to fill the dataset through the OleDbDataAdapter1.
            Me.OleDbDataAdapter1.Fill(dataSet)
        Catch fillException As System.Exception
            'Add your error handling code here.
            Throw fillException
        Finally
            'Turn constraint checking back on.
            dataSet.EnforceConstraints = True
            'Close the connection whether or not the exception was thrown.
            Me.OleDbConnection1.Close()
        End Try

    End Sub

0
 
LVL 10

Accepted Solution

by:
james-ct16 earned 1000 total points
ID: 12566605
on the assumption that objnew_order is a dataset

       Try
            grdBENEFICIARY.DataSource = Nothing
            'Empty the old records from the dataset.
            objnew_order.Clear()
            'Merge the records into the main dataset.
            objnew_order.Merge(objDataSetTemp)
'remove line            grdBENEFICIARY.SetDataBinding(objnew_order, "BENEFICIARY")
'add lines
            objnew_order.tables("BENEFICIARY").defaultview.allowdelete=false
            grdBENEFICIARY.datasource=objnew_order.tables("BENEFICIARY").defaultview
'resume your code
        Catch eLoadMerge As System.Exception
            'Add your error handling code here.
            Throw eLoadMerge
        End Try


hopefully that should do what you want

btw i noticed an error in my original post, i said "the second incolves setting table styles which is a little trickier."
While you can set teh font of the text box in edit mode via the table styles you have to manipulate a delegate of the paint command to change the font in view mode.

james

james
0
 
LVL 8

Author Comment

by:gajender_99
ID: 12566752
Thanks James You are a guru

can i have you email address for future if you dont mind

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question