473,322 Members | 1,526 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,322 software developers and data experts.

How do I change backcolor of textbox based on the value inside it?

14
Lets see if I can explain-

I have a text box (rich text box) in a form. Inside the box, some data gets put in there- specifically insurance information.

Normally, the box doesn't need to change color to alert the user there's a problem with the text that's inside, because the information is usually good.

But there are a few phrases that need to alert the user there's a problem.

For example, if the words "Not Found AS OF:" appear anywhere in the box, I need the background to show red. Or, if the words "Letter #1" appear in the box, it needs to show red. Absent of any key words, the box is normal (white).

I thought a simple If/Else statement would do the trick, but it's not.

Expand|Select|Wrap|Line Numbers
  1.  
  2.         If txtInsurance.Text = "Not Found: AS OF" Then
  3.             txtInsurance.ForeColor = Color.Red
  4.         Else
  5.             txtInsurance.ForeColor = Color.Black
  6.         End If
  7.  
  8.  
  9.  
I know that says ForeColor, I'm playing around with fore vs BackColor.

Can anyone help?
Dec 31 '10 #1

✓ answered by David Gluth

Use the “contains” function. Be very specific in your search text. For example your text says “if the words "Not Found AS OF:"” while your sample code says “"Not Found: AS OF" Notice the location of the “:” in the two – they are not alike and would not be found. Visual basic compares are case sensitive so you should also change the text to either all upper or all lower before comparing
Expand|Select|Wrap|Line Numbers
  1. If TextBox1.Text.ToUpper.Contains("NOT FOUND AS OF") Then
  2.             TextBox1.BackColor = Color.Red
  3.         End If
  4.  

2 2294
Use the “contains” function. Be very specific in your search text. For example your text says “if the words "Not Found AS OF:"” while your sample code says “"Not Found: AS OF" Notice the location of the “:” in the two – they are not alike and would not be found. Visual basic compares are case sensitive so you should also change the text to either all upper or all lower before comparing
Expand|Select|Wrap|Line Numbers
  1. If TextBox1.Text.ToUpper.Contains("NOT FOUND AS OF") Then
  2.             TextBox1.BackColor = Color.Red
  3.         End If
  4.  
Dec 31 '10 #2
RobT
14
David- thanks for your quick reply. Your solution worked for me, and was a good suggestion.
Jan 1 '11 #3

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

Similar topics

0
by: The Coolest Dolphin | last post by:
OnMouseOver & OnMouseOut event on tablerow to change backcolor of row Hi everyone, I'm looking for a way to use a mouseover/mouseout event (normally done via javascript) via Visual...
9
by: nail | last post by:
Hi. So I have a default.aspx page and 3 WebUserControls In the WebUserControl1, I have on TexBox, and in the default.aspx page I have a Button control. On the click event of the default.aspx page...
0
by: Jon | last post by:
Hi, How to change the backcolor of DataGridBoolColumn? I can change if it is a DataGridTextBoxColumn by overrides the paint method and change the textbox.BackColor however I cannot find a way...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
0
by: nikusingh | last post by:
hi all can anyone tell me how to change backcolor of last updated row of editable datagrid so i can see which last row updated. thanks NK
4
by: John Smith | last post by:
I have DataGrid with Label in one of its columns. Label should change into TextBox, when user do some specific action. How can I acomplish this?? P.S. Sorry for multiple posts in the same...
1
by: juhaszg | last post by:
I have leart that al least a dozen of customized datagrid can be bought for .NET Compact Framework. But I don't want to spend money on those because what I need is just to change backcolor of...
6
exoskeleton
by: exoskeleton | last post by:
hi dear experts...i dont know if im in the right forum but...if not please kindly move this thread.. my problem is that how to change value like this one: <script language="JavaScript"...
0
by: vidhyapriya | last post by:
Is it possible to change backcolor of the printdoument.....if so,can u help me... default backcolor is white,i want to change to pink...is it possible...
6
by: shalskedar | last post by:
In the Report i need to change the value for a textbox at runtime.Below is my code used to change the value.But i m getting an error "Can't assign value to this object". Private Sub...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.