DataGridView中动态加载DataGridViewCombobox的值

string[] str = new string[] { "123","124646","sfasf"};
dataGridView1.Columns.Add(
new DataGridViewColumn(new DataGridViewComboBoxCell()));
dataGridView1.Rows.Add(
new DataGridViewRow());
(dataGridView1.Rows[
0].Cells[0] as DataGridViewComboBoxCell).DataSource=str;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在 WinForms 的 DataGridView 动态加载并显示图片,您可以按照以下步骤进行操作: 1. 在 DataGridView 添加一个列来显示图片。可以使用 DataGridViewImageColumn 类型的列来显示图片。 2. 在代码动态加载图片,并将其赋DataGridView 对应的单元格。 以下是一个示例,展示了如何动态加载并显示图片: ```csharp // 创建一个 DataGridViewImageColumn 列来显示图片 DataGridViewImageColumn imageColumn = new DataGridViewImageColumn(); imageColumn.HeaderText = "图片"; imageColumn.ImageLayout = DataGridViewImageCellLayout.Zoom; // 设置图片布局方式 // 将列添加到 DataGridView 控件 dataGridView1.Columns.Add(imageColumn); // 加载图片并设置到单元格 string imagePath = "path_to_image.png"; // 图片的路径 Image image = Image.FromFile(imagePath); // 加载图片 int rowIndex = 0; // 要设置图片的行索引 // 创建一个 DataGridViewImageCell,并将图片赋给它 DataGridViewImageCell imageCell = new DataGridViewImageCell(); imageCell.Value = image; // 将 DataGridViewImageCell 设置到指定的单元格 dataGridView1.Rows[rowIndex].Cells["图片"].Value = imageCell; ``` 在上述示例,我们首先创建了一个 DataGridViewImageColumn 列,并设置其显示图片的布局方式为 Zoom。然后将该列添加到 DataGridView 控件。 接下来,我们加载要显示的图片,并将其赋DataGridView 的指定单元格。通过创建一个 DataGridViewImageCell 对象,并将图片赋给它,然后将该 DataGridViewImageCell 设置到指定的单元格。 请注意,上述示例的 "图片" 是 DataGridView 图片列的名称,请根据实际情况修改。同时,也可以在代码使用循环来动态加载多张图片到多个单元格。 这样,您就可以在 WinForms 的 DataGridView 动态加载并显示图片了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值