By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Bound Controls Update Events

P: n/a
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 ?
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
///
Nov 21 '05 #2

P: n/a
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 :¬)


"Cor Ligthert" wrote:
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
///

Nov 21 '05 #3

P: n/a
Lenster,

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

Cor
Nov 21 '05 #4

P: n/a
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

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.