如何获取datagridview单元格的Style.BackColor [英] How to get the Style.BackColor of a datagridview cell

查看:390
本文介绍了如何获取datagridview单元格的Style.BackColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VS2010 VB.NET,我有一个datagridview(dgv),我根据一定的值设置单元格的背景颜色。这个特定的单元格不存储任何信息,因此我不能使用该单元格中的数据来确定背景颜色。



我目前的尝试是完全失败,MSDN是仅限于设置而不是获取单元格的背景颜色。



代码我试过了

  if dgvNotes.Rows(clickedCell.RowIndex).Cells(1).Style.BackColor.ToString =Redthen 

if dgvNotes.Rows (clickedCell.RowIndex).Cells(1).Style.BackColor = Color.Red then

我是无法找到关于该主题的大量信息,因为各个编码网站上的大多数帖子都侧重于设置背景颜色。



有什么方法可以确定在单元格单击事件中写入单元格背景颜色
谢谢
$ b

  //使用vb.net 
System.Drawing.Color c = dgvNotes.Rows(e.RowInde x)的.Cells(1).Style.BackColor;

//使用c#
System.Drawing.Color c = dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex] .Style.BackColor;


Using VS2010 VB.NET, I have a datagridview (dgv) where I set the background color of cells according to a certain value. This particular cell does not store any information and therefore I can not use the data in that cell to determine the background color.

My current attempts are a complete failure and MSDN is only particular to "setting" and not "getting" the background color of a cell.

Code I've tried"

if dgvNotes.Rows(clickedCell.RowIndex).Cells(1).Style.BackColor.ToString = "Red" then

if dgvNotes.Rows(clickedCell.RowIndex).Cells(1).Style.BackColor = Color.Red then

I am not able to find much information on the topic as most of the posts on various coding sites focusses on "setting" the background color.

Is there any way that I can determine cell background color after the dgv was populated ? Thanks

解决方案

write in cell click event

// using vb.net
System.Drawing.Color c = dgvNotes.Rows(e.RowIndex).Cells(1).Style.BackColor;

//using c#
System.Drawing.Color c = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor;

这篇关于如何获取datagridview单元格的Style.BackColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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