Bound Controls Update Events

G

Guest

Hi

I'm using bound controls on a windows form such as textboxes, checkboxes
etc. which work fine except for one thing...

If you click on a checkbox for example its value changes visibly and also
the value changes in the underlying data table - but no events are fired
until you move to a new column or row.

Does anyone know of a way of being notified when the fields value starts
being changed - a begin_edit type of event ?

I know I could put code into every controls change events etc but I was
hoping there was an event which I am missing ?
 
C

Cor Ligthert

Lenster,

The value is put in the underlying datasource, when the events from the
control are evaluated.

So why not use those control events for this purpose, they are made for it.

This sentence bellow of you is in my opinion not true
If you click on a checkbox for example its value changes visibly and also
the value changes in the underlying data table

I made a sample for you to show you that, it is bellow you have to drag on a
newprojectform a checkbox and a button and than paste in this code.

I hope this helps?

Cor

\\\
Public mcheckitem As Boolean
Public Property checkitem() As Boolean
Get
Return mcheckitem
End Get
Set(ByVal Value As Boolean)
mcheckitem = Value
End Set
End Property

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.CheckBox1.DataBindings.Add("Checked", Me, "checkitem")
End Sub

Private Sub CheckBox1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles CheckBox1.Click
MessageBox.Show(mcheckitem.ToString)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(mcheckitem.ToString)
End Sub
///
 
G

Guest

Thanks Cor

You are absouletly right about the value in the underlying datasource not
changing until you move off the control I was mistaken.

I take your point about using each controls events to determine when changes
to the fields are happening but I was hoping to avoid this.
If I have to add code to the click/change events of each control it defeats
the object of binding the controls to a datasource in my opinion. I may
aswell use these click/change events to manually update my underlying
datastructures.

Currently when I get a datatable.columnchanged event (when focus moves from
a bound textbox etc) I perform validation and fire an event of my own which
the form handles and then enables/disabled the save button etc. This means
that if a value is changed but focus doesn't move from the control the save
button never gets enabled.

Not to worry I will have a rethink - Thanks for your help :¬)
 
C

Cor Ligthert

Lenster,

Did you know that it is easy possible to make by instance one Click event
for all your controls?

Cor
 
C

Cor Ligthert

Lester

I think on the validating event, and than more like this below, all typed
(partialy first pasted) here and not tested.

I hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if typeof ctr Is Textbox then
AddHandler ctr.Validate, AddressOf meValidating
end if
doSet(ctr)
Next
End Sub
Private Sub meValidating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)
Select case directcast(sender,textbox).name
Case "txtName"
'blabla
Case "txtStreet"
'blabla
Case Else
'blabla
End select
End Sub
///

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top