设置了DataGridView的列的ContextMenuStrip,点右键弹出快捷菜单后,如何得到被点击的是DataGridView的那一列呢?
解决方案 »
- 弹出了新窗体,但关闭自身无法现实!
- 如何让我的程序在安装之后直接关联指定格式的文件,并为该类文件指定一个图标
- 请教大家一个webServer的问题
- 在接口变量里面,可以放置结构体么?
- gridview如何给某一列加链接
- 排序问题 高手进
- 字符串操作!c# 大家帮我一下把 !不是很难
- [WinForm]请问DatagridBoolColumn这种类型的列里边的checkbox为何要点两次才能选中,怎么样可以解决啊?!!!
- 帮忙看看:cmd.ExecuteScalar()执行时提示“至少一个参数没有被指定值”
- 在winform中,怎么才能将一个窗体中的DataGridView中的一行数据添加到另一个窗体中的DataGridView中的去,怎么搞,求大神。
- 写了一天程序头脑有些乱,请高手帮我一下。还是时间到页面自动提交的问题
- 水晶报表的统计问题,急!!在线等
写入
e.Item.Cells[0].Attributes.Add("oncontextmenu","javascript Function");
if (irow != -1)
{
string x1 = dgv_DataList[0, irow].Value.ToString();
string x2 = dgv_DataList[1, irow].Value.ToString();
string x3 = dgv_DataList[2, irow].Value.ToString();
string x4 = dgv_DataList[3, irow].Value.ToString();
http://www.syncfusion.com/faq/windowsforms/search/689.aspx如上的方法虽说是在DataGrid,也适用于datagridview。
private void dataGridView1_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e)
{
// 获取当前行
DataGridViewRow iRow = dataGridView1.Rows[e.RowIndex];
// 弹出右键菜单
if (iRow.Selected)
e.ContextMenuStrip = contextMenuStrip1; // contextMenuStrip1为已定义好的右键菜单
else
{
// 取消所有已选择的行
dataGridView1.ClearSelection();
// 取消当前单元格
dataGridView1.CurrentCell = null;
// 设置当前行选择
iRow.Selected = true;
// 设置快捷菜单
e.ContextMenuStrip = contextMenuStrip1;
}
}
在CellClick或者其他类似事件中,让菜单Show,而不是在菜单显示后,再判断吗?
mVehicleInfo.LicenseTagNo = dgvVehicleInfoShow.CurrentRow.Cells["license_tag_no"].Value.ToString().Trim();
mVehicleTypeInfo.TypeName = dgvVehicleInfoShow.CurrentRow.Cells["type_name"].Value.ToString().Trim();
mVehicleInfo.OriginalEngineID = dgvVehicleInfoShow.CurrentRow.Cells["original_engine_id"].Value.ToString().Trim();
mVehicleInfo.OriginalEngineType = dgvVehicleInfoShow.CurrentRow.Cells["original_engine_type"].Value.ToString().Trim();
mVehicleInfo.ChangedEngineID = dgvVehicleInfoShow.CurrentRow.Cells["changed_engine_id"].Value.ToString().Trim();
这样几行代码不知道对楼主有没有用
iew.CurrentCell].value