Disable a text box when it's not adding new row?

  • Thread starter Thread starter Nick nkw
  • Start date Start date
N

Nick nkw

I want to enable a text box only when it's in "add new" status. The
BindingSource.Position just return a number. Any good way to do it?

Thanks,
 
Maybe you could enable the TextBox in the BindingSource.AddingNew
event.

==============
Clay Burch
Syncfusion, Inc.
 
How do you *know* it's in AddNew status? When they add a row to the list or
datatable? Or is that what you're asking?

Robin S.
 
I know one way to tell, check if th position of bindingSource is larger than
the counts of the table. But it seems not work well on multiple users
environment.
 
Hi,

Nick nkw said:
I want to enable a text box only when it's in "add new" status. The
BindingSource.Position just return a number. Any good way to do it?

If you are using DataSet/DataTable/DataView as a DataSource for the
BindingSource, then something like this might work:

private bindingSource_CurrentChanged(...)
{
DataRowView drv = (DataRowView)bindingSource.Current;
textBox.Enabled = drv.IsNew;
}

HTH,
Greetings
 
It really helps to use a New button also, something like the following. But
a better solution is to set up a comprehensive method that includes all
buttons and controls that are enabled/disabled as one.

Private Sub btnNew_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNew.Click
BindingSource.AddNew()
txtQuantity.Enabled = true
btnNew.Enabled = false
btnSave.Enabled = true
End Sub

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
SaveRoutine()
txtQuantity.Enabled = false
btnSave.Enabled = false
End Sub
 
The problem is when to disable the TextBox after adding? It sounds not
proper events of BindingSource suitable.
 
Back
Top