更改按钮颜色取决于数据库中的数据 [英] Change button color depends on the data from the database

查看:108
本文介绍了更改按钮颜色取决于数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变按钮的背景颜色取决于来自数据库的信息,

i有形式有多个按钮,如下图所示。



我有一个商店(商店)数据库表,此表中有一列包含商店编号和状态栏:是或否(如果租用或空)

每个商店都有一个按钮,这个按钮被命名为数据库中商店编号的编号

如何循环从数据库中检索商店数据

并更改按钮的颜色取决于数据库中的数据(如果它是空的或租用的)。



谢谢。


我尝试过:



图片:

https://d.top4top.net/p_671g4mp01.png

i want to change the backcolor for buttons depends on information from database,
i have form has multiple buttons like this picture bellow.

I have a database table for shops (stores),There is a column in this table that contains the shop number and a column for its status : Yes or No (if rented or empty)

in the model Each shop has a button and this button named as the number of the store number in the database
How can I do for loop to Retrieve store data from the database
and changes the color of the button depends on the data from the database if it is empty or rented.

thank you.

What I have tried:

picture :
https://d.top4top.net/p_671g4mp01.png

推荐答案

嘿......我做了我的自己的数据库并使用DataGridView控件将该数据库导入Visual Studio ol ...做同样的事情,然后使用它...

Hey... I made my own database and imported that database to Visual Studio using the DataGridView control... Do the same and then use this...
Public Sub ExecuteColoring()
        Try
            Dim numberRows As Integer
            numberRows = DataGridView1.Rows.Count - 2
            'We subtract 2 because first of all it gives one extra and also we have to take care that the count here starts with 0 and not 1

            Do Until numberRows = -1
                Dim btnCurrent As Button

                btnCurrent = Me.Controls.Item("Button" + (numberRows + 1).ToString)

                'Add one to the button number because our button number starts from 1 and not 0
                If DataGridView1.Rows(numberRows).Cells(1).Value.ToString.ToLower = "false" Then
                    'If it is false then the shop is not rented... So the color will be green
                    btnCurrent.BackColor = Color.Green
                Else                     'If it is true then the shop is rented and the color will be red
                    btnCurrent.BackColor = Color.Red
                End If
                numberRows -= 1
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub





另外......将此'ExecuteColoring()'添加到按钮按下事件,这样每当按下按钮时,这个东西就会执行并改变颜色...

这是预览... 预览 - https://ibb.co/kaE60w

我认为这正是你想要的......

如果你担心数据库可见......你可以人方式将其隐藏在属性中......

希望我帮助过!



Also... Add this 'ExecuteColoring()' to the button press event so that whenever you press the button this thing will execute and change the color...
Here is a preview... Preview - https://ibb.co/kaE60w
I think this is exactly what you wanted...
And if you're worrying about the database being visible... You can always hide it from the properties...
Hope I helped!


这篇关于更改按钮颜色取决于数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆