Question Label Background Color based on value in database or datagridview

Capt.Calamari

New member
Joined
Nov 27, 2019
Messages
1
Programming Experience
Beginner
Hi, newbie here
Can you change the label back color based in values of database or datagrid?
I mean if value exists in database then
label.backcolor = color.aqua
need answer if possible for my visual representation of Hotel rooms. Thanks
 
You just answered your own question:
if value exists in database then
label.backcolor = color.aqua
That is pseudo-code right there to do what you want to do. The actual code to set the label colour will be pretty much exactly what you have in the second line so all that's left is to implement the first line. That means that the actual question you want answered is how to determine whether a particular value is present in a database or DataGridView, so that's what you should be searching for information on. This is why beginners often have trouble finding solutions to their problems: they don't know what problem they're actually trying to solve. You need to first decide whether what you care about is a database or a grid or something in between, e.g. DataTable or BindingSource, and then search for information on how to look for specific values within it. Once you find such information, you can try to implement something and, if you encounter an issue doing that, you should post a specific question here.
 
That depends on the color in your database. What way is that color formatted when you receive it from your database records? Do you store your colors are strings or what?

Is the color RGBA, HEX, etc Which type? What is your table format in your database? Before giving a direct answer, these are questions which you need to answer.

Here are some of the ways you can set the various color codes :
VB.NET:
        Label1.BackColor = Color.FromArgb(210, 210, 210)
        Label1.BackColor = ColorTranslator.FromHtml("#cccccc")
        Label1.BackColor = Color.FromName("red")
 
Back
Top