473,461 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2298
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.