根据条件更改数据网格视图中图像的颜色 [英] Chnge Color of image in datagridview according condition

查看:64
本文介绍了根据条件更改数据网格视图中图像的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的朋友正在开发一个基于窗口的项目,我从SQL数据库中获取学生的记录,并在Datagridview中显示.这些学生分为两个类别,例如商业,医学和艺术.问题是,如果该学生属于商业类别,那么我想在相关学生记录前面的Datagridview列中显示一个红色圆圈,如果他是医学类别,然后是黄色圆圈,如果是艺术类别,然后是绿色圆圈,我在设计时添加了该列,并使用图像类型列来显示圆圈并在其中放置圆圈的图像,但是如何更改颜色根据我的条件这张图片.

请帮助我,如果有人对此有任何想法,我非常需要它.

谢谢与问候

Parveen Rathi

Hi.. friends a window based project is being developed by me, I am getting the record of students from SQL database and show in Datagridview. The students are divided in different - 2 category for example Commerce, Medical and Arts.The problem is that if the student is in Commerce category then I want to show a red color circle in a Datagridview column in front of associated student record, if he is in Medical category then yellow color circle and if in Arts then green color circle, I add the column at design time and take an image type column to show circle and place an image of circle in it, but how can I change the color of this image according to my conditions.

Please help me I need it very urgent if anybody have some idea about it.

Thanks & Regards

Parveen Rathi

推荐答案

Itz非常简单.示例代码为:

Itz pretty simple. Sample code is:

private void myDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  {
   int colIndex = e.ColumnIndex;
   int rowIndex = e.RowIndex;

   if (rowIndex >= 0 && colIndex >= 0)
   {
    DataGridViewRow theRow = dataGridView1.Rows[rowIndex];
    if (theRow.Cells[colIndex].Value.ToString() == "Commerce")
     theRow.DefaultCellStyle.BackColor = Color.Red;
    elseif (theRow.Cells[colIndex].Value.ToString() == "Medical")
     theRow.DefaultCellStyle.BackColor = Color.Yellow;
    if (theRow.Cells[colIndex].Value.ToString() == "Arts")
     theRow.DefaultCellStyle.BackColor = Color.Green;
   }
  }


这篇关于根据条件更改数据网格视图中图像的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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