DataGridView 图像按钮列
我想在 datagridviews 列中添加图像按钮。我添加了 datagridview 和 datagridviewbuttonColumn 但我没有将图像设置为 this 。我想在 datagridviews 列中添加带有按钮的图像,然后单击此按钮时 datagridview 行编辑或删除。请问我该怎么做!
I want to add image button in datagridviews column . I added the datagridview with datagridviewbuttonColumn
but I don't set the image to this . I want to add image with button in datagridviews column and when click this button datagridview row edit or delete. Please How do I do that!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实现此目的的一种方法是简单地重写 DataGridViewButtonCell 中的 Paint 方法,并从图形参数中调用 DrawImage。该调用必须发生在碱基调用之后。
之后,只需创建您自己的 DataGridViewButtonColumn,并将创建的 DeleteCell 设置为单元格模板:
就是这样。现在为您的 DataGridView 使用 DeleteColumn:
如果按钮单击的结果操作取决于单元格行,请确保正确处理单击,即捕获单元格行索引。
One way this can be achieved is to simply override Paint method from DataGridViewButtonCell and and call DrawImage form the graphics parameter. The call must occur after base call.
After that simply create your own DataGridViewButtonColumn, and set created DeleteCell as the cell template:
That's it. Now use DeleteColumn for your DataGridView:
If the resulting action of button click depends on cell row, make sure to handle the clicks right, that is, to catch the cell row index.
虽然
DataGridView
有ButtonColumn
,但它并不直接提供显示图像的方法。以下链接可以指导您逐步完成任务:
DataGridView 图像按钮单元格
希望这会有所帮助...
Though
DataGridView
hasButtonColumn
it does not directly provides way to display images.The following link may guide you step by step to achieve your task:
DataGridView Image Button Cell
Hope this helps...
您可以使用从 DataGridViewImageButtonCell 类继承的自定义 DataGridViewImage 类,如下所示
另外,请检查 这个主题也是如此
You can use customize DataGridViewImage class that inhrit from DataGridViewImageButtonCell class as below
And also, check this topic as well
只需创建带有图像列的数据表并向其中添加图像
dtMain.Columns.Add("ImageColumn", typeof(Image));
dtMain.Rows.Add(Image.FromFile(photopath + "1.jpg"));
然后在事件 dataGridViewMain_CellContentClick 上编写以下代码
在 http://tablegridview.blogspot.in 下载完整代码
Simply create datatablewith image column and add image to it
dtMain.Columns.Add("ImageColumn", typeof(Image));
dtMain.Rows.Add(Image.FromFile(photopath + "1.jpg"));
Then On event dataGridViewMain_CellContentClick write following code
Download full code at http://tablegridview.blogspot.in
可以在 asp:ButtonColumn 的 Text-Property 中提供 HTML。所以你实际上可以做这样的事情:
呈现如下(HTML):
It is possible to provide HTML in the Text-Property of asp:ButtonColumn. So you can actually do something like this:
This is rendered as follows (HTML):