如何基于数据库中的数据动态分配Datagridview单元格值? [英] How to dynamically assign Datagridview cell values based on data from my database?

查看:61
本文介绍了如何基于数据库中的数据动态分配Datagridview单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Winform项目中有一个Datagridview.Datagridview由我数据库中的数据填充.

I have a Datagridview on my Winform project. The Datagridview is populated by data from my database.

我的数据库表上有3列: id name status .

I have 3 columns on my database table: id, name, status.

我想做的是,根据我从数据库中获得的状态字符串(在线"或离线"),我想在单元格中放置一个图像,而不仅仅是显示在线或在线字符串.离线.

What I want to do is, based on the status string I get from my database ("Online" or "Offline"), I like to put an image in the cell, instead of just displaying a string of either Online or Offline.

例如:如果状态为在线",我想在单元格上显示我指定的在线图像/图标.

ex.:If the status is Online, I'd like to have my designated online image/icon on the cell.

有人知道如何解决这个问题吗?

Anyone have ideas how to approach this?

推荐答案

我会在

您的数据网格也需要附加到 DataBindingComplete

Your datagrid would need to attach to the DataBindingComplete as well

此答案也可能有用:

https://stackoverflow.com/a/8182203/2589202

这篇关于如何基于数据库中的数据动态分配Datagridview单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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