 |
| VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1).
** Please don't post code questions here **
For issues specific to a particular language in .NET, please see the other forum categories. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 16th, 2004, 07:28 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
working with editable buttons
Hi there,
Ok, I'm in trouble.
I designed an onscreen keyboard for a registration system in restaurants that can be handled by touchscreen (65 buttons).
The text and name of the buttons need to be dynamicly loaded with data from my database.
I can put it in hard code (but I am lame and dont want to write those few lines 65 times).
dim thisButton as clsButton = new clsButton()
thisButton = thisButton.findByPK("btn1")
btn1.text = thisButton.addText
this works fine but I want to put in in a for ... next loop.
The problem occurs when I need to define wich button needs to be set.
I need something like
for ...
strText = "btn" & i
me.controls(strText).text = thisButton.addText
next ....
Offcourse this doesn't work cause strText is string and not of type button.
Who can help me how I can convert the string to type button and still have it pointing to the button I named btn1.
Hope someone in the WWWorld can help me.
This is my final project before I graduate.
Thank you.
Frank
__________________
Frank Vandeven
Belgium
|
|

March 17th, 2004, 08:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Try:
Code:
CType(Me.Controls(strText), Button).Text
You may have to use the FindControl method to get the control by ID.
|
|

March 17th, 2004, 09:48 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
bmains- I'm not sure that will work.
Usually, when you need to find a control by name, you need to use something like this:
CType(Me.FindControl(strText), Button).Text
|
|

March 17th, 2004, 02:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
I thought the way to find it was FindControl, but I haven't been developing windows applications, and I didn't want to make that assumption.
Thanks planoie
Brian
|
|

March 17th, 2004, 04:55 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for the response.
BUT
When I try to use me.FindControls(..
I get the error "FindControl is not a member of "projectname,formName""
do I need to import or inherit something?
I tried a lot of things but can't get it to work.
Might there be a problem cause my buttons are located in groupboxes?
Frank
Frank
|
|

March 17th, 2004, 06:07 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
<s>You have to look in the controls collection where you expect the control to be.
Code:
Me.Controls
+-Control1
| +-ControlA
| +-ControlB
+-Control2
+-ControlC
+-ControlD
To find ControlC, you need to use Control2.FindControl(), instead of Me.FindControl.
(Unless I'm completely off my rocker, which is entirely possible.)
</s>
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

March 18th, 2004, 09:13 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
That sound's right, since the groupbox is a container control, you should query that control using the FindControl Method.
However, I can't find the FindControl method in the list of methods for the GroupBox, and I'm going to assume the same for the Windows Form. You need to try to find the equivalent, or loop through the child controls with a for each mechanism to access the child controls (child controls of the group boxes).
Hope this helps.
|
|

March 18th, 2004, 05:20 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Apparently I am off my rocker. I was informed off-list that FindControl() is not available in Windows.Forms programs. I don't work with them much so I shouldn't have suggested it. My apologies for any misdirection.
|
|

March 18th, 2004, 05:28 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help.
I think it's going to be a lot of typing afterall.
do you think this will slow down the start up cause it needs 68 in/outs to my dbase?
Frank
|
|

March 18th, 2004, 07:57 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK, I'm true searching .
I found a way to handle it.
Dim arrButtons(63) As Button
Private Function LoadButtons(ByVal strBtn As String, ByVal arrBtn As Button)
Dim thisKnop As knop = New knop()
Try
thisKnop = thisKnop.findKnopByPK(strBtn)
arrBtn.Text = thisKnop.Opschrift
Catch
End Try
End Function
Public Function fillButtonArray()
fillArray()
Dim i As Integer = 1
For i = 0 To arrKnoppen.Length - 1
LoadButtons("btn" & (i + 1).ToString, arrKnoppen(i))
Next
End function
Public Function fillArray()
arrButtons(0) = btn1
arrKnoppen(1) = btn2
arrKnoppen(2) = btn3
arrKnoppen(3) = btn4
arrKnoppen(4) = btn5
arrKnoppen(5) = btn6
......
End Function
This works, only the first time it gets loaded it takes +/- 1.5 secs so that's ok with me
Maybe this can be usefull for somebody else who has the same problem.
Thanks y'all
Frank
|
|
 |