日期:2014-05-18 浏览次数:21156 次
用DataGridView控件 public System.Drawing.Image GetImage(string path) { System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open); System.Drawing.Image result = System.Drawing.Image.FromStream(fs); fs.Close(); return result; } private void demoGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { //这里写判断条件,根据条件显示不同图片 if (demoGrid.Columns[e.ColumnIndex].Name.Equals("Image")) { string path = System.Windows.Forms.Application.StartupPath + @"/1.gif"; e.Value = GetImage(path); } } //设置右键菜单 private void dgvList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { if (dgvList.Rows[e.RowIndex].Selected == false) { dgvList.ClearSelection(); dgvList.Rows[e.RowIndex].Selected = true; } if (dgvList.SelectedRows.Count == 1 && e.ColumnIndex != -1) { dgvList.CurrentCell = dgvList.Rows[e.RowIndex].Cells[e.ColumnIndex]; } dgvList.ContextMenuStrip = contextMenuStrip1; } else { dgvList.ContextMenuStrip = null; return; } } } //执行方法 private void tsmDelete_Click(object sender, EventArgs e) { }
------解决方案--------------------