我想动态地添加不同的图像到c#窗体datagridview行标题。它应该像检查任何单元格值,如果它> 10显示一些图像,否则显示其他图像。如何做到这一点?请帮助我...........如何添加不同的图标/图像到c#中的datagridview行标题?
1
A
回答
2
到GridView
添加OnRowDataBound事件处理程序在事件处理程序 - 检查头部和处理每列相应
protected virtual void OnRowDataBound(GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Header) {
// process your header here..
}
}
欲了解更多信息请点击这里:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewroweventargs.row.aspx
0
2
你可以将图像添加到DataGridView.RowPostPaint事件中的DataGridView行标题中。
下面是在CodeProject上的文章,似乎描述的这个相当不错的链接(我还没有尝试过对自己代码):Row Header Cell Images in DataGridView
可以使用RowPostPaint事件提取要测试对值确定要显示哪个图标。通过使用该事件的RowIndex属性与你感兴趣的列的索引值做到这一点
像这样的东西应该作为一个起点:
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) {
// As an example we'll check contents of column index 1 in our DGV.
string numberString = dataGridView1.Rows[e.RowIndex].Cells[1].Value as string;
if (numberString != null) {
int number;
if (Int32.TryParse(numberString, out number)) {
if (number > 10) {
// Display one icon.
} else {
// Display the other icon.
}
} else {
// Do something because the string that is in the cell cannot be converted to an int.
}
} else {
// Do something because the cell Value cannot be converted to a string.
}
}
+0
Thiks很多。这对我的程序有用..... thnx再次... – hmlasnk
相关问题
- 1. 如何在JFrame的标题栏中添加图像图标?
- 2. 将图像添加到.net datagridview的标题
- 3. 我们如何添加drupal7主题的不同徽标(图像)标题
- 4. 添加标题和图标图像QProgressDialog
- 5. UITableView为图像图标添加标题
- 6. 如何添加不同的链接到标题中的两个图像
- 7. 将表中的图像对齐并添加标题标题行
- 8. 如何将图像和标题添加到表视图的标题IOS
- 9. 将图像图标添加到UIPickerView行
- 10. 如何将相关标题添加到不同div中的随机图像?
- 11. flexslider图像如何添加标题
- 12. 添加图像标题
- 13. 添加选中标记图像到选中的同一行UITableView
- 14. 如何在标题文本后的网格视图标题中添加图像
- 15. 如何将图像和标签添加到UINavigationBar作为标题?
- 16. 如何添加图像,而不是标题文本中的Android
- 17. 如何在c#中将图标添加到图标?
- 18. c#DataGridView每行添加图像
- 19. 如何将图像替代和标题标签添加到wordpress图像
- 20. Android:如何设置不同的布局标题和标题栏图标图像
- 21. 添加图像到表单标题
- 22. 将URL添加到Photoswipe图像标题
- 23. 将图像添加到Wordpress标题
- 24. 将标题和图像添加到NSStatusItem
- 25. 将图像添加到C#DataGridView
- 26. 如何将图标添加到导航抽屉中的标题?
- 27. 如何将图像添加到标签?
- 28. 在UITableview的标题视图中添加动态图像到UIView
- 29. 添加图像或图标到primefaces选项卡标题
- 30. 如何将图标(图像,徽标..)添加到状态栏
将图像添加到headertemplate并在onrowdatabound事件中隐藏它或将其分配给一个url。 – anami