EventHandler and Binding?

mmb

Active member
Joined
Aug 1, 2004
Messages
42
Programming Experience
1-3
Q.1)
I am calling a single function on all the textbox control KeyPress Event, my code has increased alot in the signature of eventhandler.

What I want to raise a single KeyPress Event on all textbox control.
I know this is possible but dont know how. Pls Help me out

Q.2)
How to bind GroupBox with Radio Buttons in it, with a single single column of a table having Boolean DataType?

This Question I have asked for 2nd time. I hope I get the solution this time.
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
1) As always with .NET there are several ways to accomplish this.
One way would be to include each control's event in the handles clause. For Example:
VB.NET:
Private Sub TextBoxs_KeyPress(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.KeyPressEventArgs) _
  Handles TextBox1.KeyPress, TextBox1.KeyPress, TextBox3.KeyPress
'...
Another way would be to add the event handler to all the textbox controls on the form during the load procedure:
VB.NET:
Dim ctrl As Control
For Each ctrl In Me.Controls
    If TypeOf ctrl Is TextBox Then
        Dim txtbx As TextBox = CType(ctrl, TextBox)
        AddHandler txtbx.KeyPress, AddressOf TextBoxs_KeyPress
    End If
Next
'Then create the procedure with the same signature as the KeyPress event:
Private Sub TextBoxs_KeyPress(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.KeyPressEventArgs)
'...
I don't understand what you're trying to do in the second question.
 

mmb

Active member
Joined
Aug 1, 2004
Messages
42
Programming Experience
1-3
This is now I have binded my texbox.. named Name_txt with the dataset table "Staff " and column "Name"
Code:
Name_txt.DataBindings.Add(
New Binding("Text", ds.Tables("Staff"), "Name"))

Now I have a field in my table IsStaff which is boolean type.
On my windows form I have used a GroupBox which contains two radio buttons ..TeachingStaff and NonTeachingStaff.

What I want is to bind the groupbox with the IsStaff Column of Staff table in dataset.

Hope u understand my question now.
And thanks for the previous help.
 
Top Bottom