gajender_99
asked on
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
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
ASKER
hi hames can you provide the systax for locking on deletion as i am a new to .net
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
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
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
ASKER
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
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
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
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
ASKER
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(objDataSetT emp)
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(objData SetTemp)
grdBENEFICIARY.SetDataBind ing(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
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(objDataSetT
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(objData
grdBENEFICIARY.SetDataBind
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
Try
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to fill the dataset through the OleDbDataAdapter1.
Me.OleDbDataAdapter1.Fill(
Catch fillException As System.Exception
'Add your error handling code here.
Throw fillException
Finally
'Turn constraint checking back on.
dataSet.EnforceConstraints
'Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close(
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks James You are a guru
can i have you email address for future if you dont mind
can i have you email address for future if you dont mind
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