PC Review


Reply
Thread Tools Rate Thread

Bound Controls Update Events

 
 
=?Utf-8?B?TGVuc3Rlcg==?=
Guest
Posts: n/a
 
      18th Aug 2004
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 ?


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
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
///


 
Reply With Quote
 
=?Utf-8?B?TGVuc3Rlcg==?=
Guest
Posts: n/a
 
      18th Aug 2004
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
> ///
>
>
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
Lenster,

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

Cor


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data-bound listbox prevents other controls from handling events! Rob Richardson Microsoft VB .NET 2 29th Aug 2004 11:04 PM
update bound controls with query Donovan Microsoft Access Forms 1 23rd Mar 2004 06:32 PM
Confused about bound controls update of dataset STom Microsoft ADO .NET 0 30th Oct 2003 12:18 AM
Controls bound to DataRelation Update problem David Adams Microsoft ADO .NET 3 8th Oct 2003 08:00 PM
Update Command / Data bound controls Problem Rob Williams Microsoft ADO .NET 1 2nd Sep 2003 07:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:41 AM.