two queistions about textboxes

yaniv

Well-known member
Joined
Apr 15, 2002
Messages
162
Location
israel
i have two problems with my multi text boxes form:

1) how can move from one textbox to another with the "enter" key, and dont just with the "tab"?

2) when i pass the data to the database i do use "trim" to cut off the spaces, but when i get the data in the text box and i want to update it, there is allways "something" in the text box, even if it was empty in the sending. i have to "erase" the blank textbox and then to rewrite. can you make a textbox that gets a empty data to remain empty?

it does happend even if i use this:

if isdbnull (firstname) = true then firstname = ""

and the textbox of firstname is "full" of spaces.

thanks in advance
yaniv
 
well the answer to your enter key problem is this :
Code:
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = 13 Then
            TextBox2.Focus()
        End If
 
To get a null value there must be a null value on the database, be sure to assign the null value when you send the query to the DB

Code:
Q = "INSERT INTO TABLE (COL1, COL2, COL3) VALUES (1,NULL, YOUR NAME)"

to check a textbox if it has something you can try the following

[VB]
If Trim(textbox1.Text) = "" Then
[/VB]

then when you make the select query to the database you will get the null value, here is a more complete example

[VB]

Q = "INSERT INTO TABLE(COL1, COL2, COL3) VALUES (1,"

If Trim(TextBox1.Text) = "" Then
Q = Q & "NULL,"
Else
Q = Q & TextBox1.Text & ","
End If

Q = Q & "3)"

[/VB]

The use of the trim as you said will cut the blank spaces to the left and right of the text, so if your textbox is blanks or with spaces inserted by the user the condition will always result in true, otherwise if the textbox has text will result in false

Hope this helps you
 
the two solution worked, but the "dirty" textboxes is still there. I think the problem is because I use right align textboxes (as a Hebrew speaker), I could solve it in my char textboxes.

How ever, about my first question, I dont want to make a event handler to each textbox, so I tried that:

Code:
if e.keycode = 13 then
o = me.control.  control in focus
me.control (o+1).focus
end if

the problem is I dont know how to get the number of control in focus.
 
You can use this code to focus the next control of the form:
Code:
      Me.GetNextControl(Me.ActiveControl, True).Focus()
Substitute "True" for "False" to make it go backwards.
 
Back
Top