所以我的网络有一个DataGridView
IP地址,现在我正在尝试构建一些东西,允许我在右键单击特定行后打开该IP地址的资源管理器。
这是我已经获得的代码:
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenuStrip menu = new ContextMenuStrip();
int position = dataGridView1.HitTest(e.X, e.Y).RowIndex;
if(position >= 0)
{
menu.Items.Add("OpenExplorer").Name = "Open Explorer";
}
menu.Show(dataGridView1, new Point(e.X, e.Y));
menu.ItemClicked += new ToolStripItemClickedEventHandler(menu_ItemClicked);
}
}
void menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
foreach (DataGridViewRow linha in dataGridView1.SelectedRows)
{
switch (e.ClickedItem.Name.ToString())
{
case "OpenExplorer":
Process.Start(@"\\" + linha.Cells[0].Value.ToString());
break;
}
}
}
但它实际上不起作用,因为显示错误说该路径不存在。你有任何想法如何解决它?我如何获得所选行?