Visual Basic Development Bookmark and Share   
 Home > Visual Basic Power Packs > Resize Textbox in Datarepeater
 

Resize Textbox in Datarepeater

I want to be able to resize a textbox when a user clicks on a textbox within a datarepeater. So the textbox will start out as a single line, but would expand to be multiline to better allow the user to enter text. When the user's mouse leaves the textbox I want it to return to the original size. I tried changing the textbox.height, but nothing happens. Any help is appreciated.
http://blogs.windowsclient.net/wwade73/
Wade73  Tuesday, August 25, 2009 12:17 PM

Well, this should be easily done by setting the multiline property of the textbox.
For example,

Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
Me.TextBox1.Multiline = True
Me.TextBox1.Height = 100
End Sub

Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
Me.TextBox1.Multiline = False
End Sub

Hope this would help.


John Chen -- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
John Chen MS  Saturday, August 29, 2009 10:32 PM

Well, this should be easily done by setting the multiline property of the textbox.
For example,

Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
Me.TextBox1.Multiline = True
Me.TextBox1.Height = 100
End Sub

Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
Me.TextBox1.Multiline = False
End Sub

Hope this would help.


John Chen -- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
John Chen MS  Saturday, August 29, 2009 10:32 PM
John,

I had already tried that (forgot to mention I used multiline = true) but nothing happens.

Wade
http://blogs.windowsclient.net/wwade73/
Wade73  Monday, August 31, 2009 4:16 PM

Hi Wade,

Sorry I have not tested my code with a DataRepeater as I thought your issue is on MultipleLine = true.
And yes you are right, it is nto straight-forward on the DataRepeater to realize it as theTextBox control are cloned inthedisplayed row.

Change to the following code, it should work:

Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
Dim txtBox As TextBox = TryCast(sender, TextBox)
If (txtBox IsNot Nothing) Then
txtBox.Multiline = True
txtBox.Height = 100
End If
End Sub

Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
Dim txtBox As TextBox = TryCast(sender, TextBox)
If (txtBox IsNot Nothing) Then
txtBox.Multiline = False
End If
End Sub


You can see that inside the event hadler, we should not assume the TextBox control is me.TextBox1, which is just a template. You will need to use the one from sender.

Hope this time it will solve your issue.

Thanks!


John Chen -- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
John Chen MS  Monday, August 31, 2009 10:48 PM

You can use google to search for other answers

Custom Search

More Threads

• DataRepeater problem when form inactive
• Set Paper Tray using Printer object?
• DDE Link
• VB 2008 Moving Lineshape
• how it work of DataRepeater ?
• Databound ComboBox in a DataRepeater
• Inherit SimpleShape
• PrintForm documentation/examples
• winsock help
• Labelprinting with Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6