Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Quickly lock & unlock lots of fields for editing - best way/practice
 

Quickly lock & unlock lots of fields for editing - best way/practice

Just now learning how to do this stuff in VB.Net

I have build a functional form to pull SQL Server master-detail data and present it to the user. My concern is that the controls for the detail fields (a bunch of textboxes) are all freely editable, and the users can inadvertantly change data. I want them to consciously ELECT to go into edit mode. Also, I don't want to commit changes simply because they move off the current row - I want them to be forced to either commit or cancel the edit.

Is there any single way to do this that is uniformly considered the standard?

Duke Carey  Sunday, December 02, 2007 7:56 PM

Hi Duke Carey,

For your question how to not allow use edit the field. I would place these textboxes in a panel and set the panel’s Enabledto false when I don’t want to allow the users edit the field.

I didn’t quite get your second question. If you mean you want to ask the use to commit the changes to the database when the current row has been changed, you can check RowState of current row, if it is not RowState.Unchanged, write back to the database.

Code Block

If currentDataRow.RowState <> DataRowState.Unchanged Then

'do update stuff here

End If

If you mean you don’t want to write back to the underlying data source unless the user clicks on the commit button, you can set the DataSourceUpdateMode to false DataSourceUpdateMode.Never of Binding object and call the WriteValue method in the commit button click handler.

Code Block

'set the DataSourceUpdateMode to DataSourceUpdateMode.Never

Me.textBox1.DataBindings.Add("Text", dt, "col", True, DataSourceUpdateMode.Never)

Private Sub btnCommit_Click(ByVal sender As Object, ByVal e As EventArgs)

'write back to the underlying data source

Me.textBox1.DataBindings("Text").WriteValue()

End Sub

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, December 06, 2007 9:42 AM

Hi Duke Carey,

For your question how to not allow use edit the field. I would place these textboxes in a panel and set the panel’s Enabledto false when I don’t want to allow the users edit the field.

I didn’t quite get your second question. If you mean you want to ask the use to commit the changes to the database when the current row has been changed, you can check RowState of current row, if it is not RowState.Unchanged, write back to the database.

Code Block

If currentDataRow.RowState <> DataRowState.Unchanged Then

'do update stuff here

End If

If you mean you don’t want to write back to the underlying data source unless the user clicks on the commit button, you can set the DataSourceUpdateMode to false DataSourceUpdateMode.Never of Binding object and call the WriteValue method in the commit button click handler.

Code Block

'set the DataSourceUpdateMode to DataSourceUpdateMode.Never

Me.textBox1.DataBindings.Add("Text", dt, "col", True, DataSourceUpdateMode.Never)

Private Sub btnCommit_Click(ByVal sender As Object, ByVal e As EventArgs)

'write back to the underlying data source

Me.textBox1.DataBindings("Text").WriteValue()

End Sub

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, December 06, 2007 9:42 AM

You can use google to search for other answers

Custom Search

More Threads

• dataview in a listbox
• DataAdapter.Update not working
• Extract data from a datagrid with columns of textboxes
• KeyDown Search in DataGridView
• refresh the data table disable to select
• Sharing same data on two forms
• User control with datagridview
• The v2 DatePicker doesn't support null databinding (bug?)
• DataGridView looses its CellStyle
• binding dropdownlist to array