473,412 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Problem changing text of custom control based on text of another custom control

Hi - I am using custom textboxes and I need to be able to set the Text on txb1 based on the Text of txb2. I have simplied my code to the following:
Expand|Select|Wrap|Line Numbers
  1.     Public Class customtextbox
  2.         Inherits TextBox
  3.         Public Event ControlReset()
  4.         Public Sub New(ByVal strP As String)
  5.             MyBase.New()
  6.             AddHandler customtextbox.ControlReset, AddressOf Me.test
  7.         End Sub
  8.         Public Sub test()
  9.             Me.Text = "chips" + Me.Name
  10.         End Sub
  11.         Public Sub ProcessAlert()
  12.             RaiseEvent ControlReset()
  13.         End Sub
  14.         Private Sub customtextbox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
  15.             Dim cT As Control
  16.             Dim cS As customtextbox
  17.             If Me.Name = "txb1" Then
  18.                 If Me.Text = "fried" Then
  19.                     For Each cT In frmTest.Controls
  20.                         If cT.Name = "txb2" Then
  21.                             cS = cT
  22.                             Call cS.ProcessAlert()
  23.                         End If
  24.                     Next
  25.                 End If
  26.             End If
  27.         End Sub
  28.     End Class
  29.  
and the form code is:
Expand|Select|Wrap|Line Numbers
  1. Public Class frmTest
  2.     Public Sub New()
  3.         InitializeComponent()
  4.         Dim txb1 As customtextbox
  5.         Dim txb2 As customtextbox
  6.         txb1 = New customtextbox("params for txb1")
  7.         txb1.Name = "txb1"
  8.         txb1.Location = New Point(10, 10)
  9.         txb1.Size = New Point(200, 20)
  10.         Me.Controls.Add(txb1)
  11.         txb2 = New customtextbox("params for txb2")
  12.         txb2.Name = "txb2"
  13.         txb2.Location = New Point(10, 30)
  14.         txb2.Size = New Point(200, 20)
  15.         Me.Controls.Add(txb2)
  16.     End Sub
  17. End Class
  18.  
So, when txb1 looses focus, if its Text is "fried", then it sets off txb2's ProcessAlert function. I had tried to change the value of txb2 Text in ProcessAlert function, but didnt work, so I tried to get it to raise an event instead, which then tries to set the Text property. However I still cant set txb2's Text property. The Text property seems to be set for the duration of the "life" of the Event handler. When I step through the forms controls within the Event handler, the changed Text value is there, but not outside of the Event handler.

Any suggestions???
Many thanks
Jan 11 '10 #1
2 1386
tlhintoq
3,525 Expert 2GB
I'm a C# guy, not a VB guy, so someone correct me if I am wrong here...
Expand|Select|Wrap|Line Numbers
  1.             Dim cS As customtextbox
  2.             If Me.Name = "txb1" Then
  3.                 If Me.Text = "fried" Then
  4.                     For Each cT In frmTest.Controls
  5.                         If cT.Name = "txb2" Then
  6.                             cS = cT
  7.                             Call cS.ProcessAlert()
  8.  
The event is being fired in the newly created cS textbox not in located cT textbox. I suspect there is no reason for the cS control at all and could be simplified as
Expand|Select|Wrap|Line Numbers
  1. If Me.Name = "txb1" Then
  2.                 If Me.Text = "fried" Then
  3.                     For Each cT In frmTest.Controls
  4.                         If cT.Name = "txb2" Then
  5.                             Call cT.ProcessAlert()
Of course since this is a custom control we have no idea what .ProcessAlert() does, so if the problem resides there....
Jan 11 '10 #2
Thanks for the reply. I had to use the cS as the ProcessAlert() is a sub within the custom control, and thus not available from a standard control type. The ProcessAlert just raised an event on another custom control that changes its text.

I have changed my coding and taken most of the subs out of the custom control and put them in the form that creates them (there was a lot more code, this was just a simple example I created to try and solve the problem), and also passed the form to the custom controls, so the custom controls have direct access to the subs. Now that I am calling the subs from the form rather than the custom controls, it seems to work OK.

Cheers
Jan 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Marina | last post by:
Here is the problem. If 2 different properties on the same (or different) control are bound to the same data column, changing the Text property and calling EndCurrentEdit discards the new value. ...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
3
by: qwerty | last post by:
I´m new to ASP.Net. My workmate has some experience with it. He claimed that in ASP.Net working with frames is much simpler than it was ASP. I asked explanation but he couldn't give me such. (a...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
2
by: osmarjunior | last post by:
Hello there... I have a custom user control, in which i put a panel on the top. In the Paint event of the panel, i have the following code: VisualStyleRenderer x = new...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
12
by: Ron M. Newman | last post by:
Hi, I can load an assembly using the Assembly.Load(....) However, I'd like dynamic loading of assemblies to be identical to putting an assembly reference in your VS2005 project. and yes, I...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.