简体   繁体   English

在datagridview中单击图像时,如何获取位图名称?

[英]How do I get the Bitmap name when I click the image in datagridview?

I am trying to click on an image in a datagridview and then write its image/file name into a textbox so I can access this from elsewhere. 我试图单击datagridview中的图像,然后将其图像/文件名写入文本框,以便可以从其他位置访问它。

First I try just a small app to make sure I can make it all work. 首先,我尝试仅使用一个小型应用程序,以确保可以正常运行。 A Dialog contains the dataviewgrid and I put a bitmap into it as below: 一个对话框包含dataviewgrid,我将一个位图放入其中,如下所示:

public ChooseFormat()
        {

            InitializeComponent();
            dataGridView1[0,0].Value = new Bitmap(@"C:\a\eggs\grid_app\grid_app\bin\Debug\graphics\1L5HQ60.bmp"); 
        }

Now I click on the image but all the things I have tried I cannot get hold of the file name. 现在,我单击该图像,但是我尝试的所有操作都无法获取该文件名。 The closest I get is below but this returns "System.Drawing.Bitmap" and not the file name. 我得到的最接近的是下面,但这将返回“ System.Drawing.Bitmap”,而不是文件名。 I am sure this must just be a tweak here to make it work but I have tried teh few things I know and nothing is working. 我敢肯定,这只是在这里进行一些调整才能使其起作用,但是我已经尝试了一些我所知道的事情,但是没有任何效果。

        void DataGridView1CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtbx_choice.Text = dataGridView1[0,0].Value.ToString();
        }

Drilling into the cells's data in the debugger doesn't bring up any info on the source of it. 在调试器中钻取单元的数据不会在源上显示任何信息。 Maybe I have overlooked something.. 也许我忽略了一些东西。

One simple solution is to store the filename in the cell's Tag property: 一种简单的解决方案是将文件名存储在单元格的Tag属性中:

string fileName = @"C:\a\eggs\grid_app\grid_app\bin\Debug\graphics\1L5HQ60.bmp";
dataGridView1[0,0].Value = new Bitmap(fileName ); 
dataGridView1[0,0].Tag = fileName ; 

Now you can always access it: 现在您可以随时访问它:

string displayedFile = dataGridView1[0, someRow].Tag.ToString();

我已经在同一窗体上放置了一个图片框,这就是我在图片框中显示ImageColumn的数据(Image)的方式

pictureBox1.Image = (Image)dataGridView1[0, 0].Value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取要在MVC 2中显示的位图图像 - How do I get a bitmap image to show in MVC 2 如何获取WatiN图像元素的位图? - How do I get a bitmap of the WatiN image element? 如何在C#中获取位图图像的背景色? - How do I get the background color of Bitmap Image in c#? 如何以编程方式单击DataGridView的单元格? - How do I click on a Cell of a DataGridView programmatically? 当我单击datagridview中的行时如何从datagridview获取任何数据? - How to get any data from datagridview when I click on the row in datagridview? 如何清除datagridview中的列名 - How do I clear a column name in datagridview 单击链接时,如何在“ Webbrowser”事件中获取链接属性(页面名称)? - How do I get the link attributes (page name) in the “Webbrowser” event when I click a link? 右键单击 DataGridView 的列标题时,如何正确定位上下文菜单? - How do I correctly position a Context Menu when I right click a DataGridView's column header? 如何在DataGridView中获取选中的DataRow? - How Do I Get the Selected DataRow in a DataGridView? 当我在 C# 中有多个 datagridviews 时,如何获取当前选定的 datagridview 的名称? - How can I get the name of the current selected datagridview when I’ve multiple datagridviews in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM