具有不同BackColor行的DataGridView [英] DataGridView with Rows of Different BackColor

查看:70
本文介绍了具有不同BackColor行的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有一列的DataGridView. DataGridView的行数将根据用户输入而变化.为此,我使用了可以正常工作的以下代码:

I created a DataGridView with one Column. The number of rows of the DataGridView will vary according to user input. To do that I used the following code which works fine:

 ColorForm.DGV1.RowCount = CInt(TextBox1.Text)

请查看以下屏幕截图:

TextBox1显示课程数的所有整数的总和 列,该列将根据用户输入而不同(我的意思是,这里的输入是10、5、5(总计20).但是输入可能是10、3、5、8(总计26).然后DGV1将显示26行而不是20行).我已经成功完成了这一部分.

TextBox1 shows the sum of all the integers of Number of Courses column which will vary according to user input (what I mean is-here the input is 10, 5, 5 (total 20). But the input could be 10, 3, 5, 8 (total 26). Then the DGV1 will show 26 rows instead of 20). I successfully completed this part.

DGV1行的背景色不固定.请允许我举例说明.对于上述情况(快照),DGV1将总共有20行.在这20行中,DGV1的前10行的底色必须为黄色(255,255,0).底色 DGV1接下来的5行中的橙色需要为橙色. DGV1的最后5行的背景色必须为绿色.黄色,橙色,绿色不是固定的.用户可以选择具有不同课程数量的不同颜色.例如:

The backcolor of the rows of DGV1 is not fixed. Allow me to explain with an example. For the above case (screershot), the DGV1 will have total 20 rows. Among those 20 rows, backcolor of the first 10 rows of the DGV1 needs to be yellow (255,255,0). The backcolor of the next 5 rows of the DGV1 needs to be orange. The backcolor of the last 5 rows of the DGV1 needs to be green. The yellow, orange, green colors are not fixed. User may chose different colors with different Number of Courses. For example:

我要说的是DGV1行的背景色不固定.会有所不同.现在,当我单击按钮时,如何显示具有不同背景色的行数不同的DGV1?我认为还没有完成,但我仍然 没有做到这一点.如果您给我展示一种方法,那就太好了.

What I am trying to say is the backcolors of the rows of DGV1 are not fixed. It will vary. Now how can I show the DGV1 with different number of rows having having different BackColor when I click a button? I reckon it's not that completed but still I am failing to do it. It would be awesome if you show me a way.

PS:我之前发布了一个类似的帖子.但是我有一个固定的背景色行的解决方案.我试图根据该解决方案编写代码,但是没有用.  

PS: I posted a similar thread before. But there I got a solution with fixed backcolored rows. I tried to write codes based on that solution but it didn't work.  

失败

推荐答案

首先说您创建了一个带有ONE列的DGV,然后继续显示有四个列的示例.那是我停止阅读的地方.......................

You start off by saying you created a DGV with ONE column, then proceed to show an example where there are FOUR columns. That's where I stopped reading ...................


这篇关于具有不同BackColor行的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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