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

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

问题描述

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

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.

我目前的尝试完全失败,MSDN 只针对设置"而不是获取"单元格的背景颜色.

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

我试过的代码"

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.

在填充 dgv 后,有什么方法可以确定单元格背景颜色吗?谢谢

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

推荐答案

写入单元格点击事件

// 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天全站免登陆