Stoping the deletion of record on a datagrid

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
LVL 8
gajender_99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

james-ct16Commented:
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
gajender_99Author Commented:
hi hames can you provide the systax for locking on deletion as i am a new to .net
0
james-ct16Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

gajender_99Author Commented:
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
james-ct16Commented:
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
gajender_99Author Commented:
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
james-ct16Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gajender_99Author Commented:
Thanks James You are a guru

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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.