通过单击链接,我想打开其他链接的表单 [英] By clicking a link i want to open form for diffetnt links
本文介绍了通过单击链接,我想打开其他链接的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In my Datagridview i want keep a column as link,by clicking that link i want to open a new form like this for each link column cell i want to get different forms for by cliking a link,please help me in code. randomly by clicking a link in datagridview. how Can i can you people, please give me answer for this question.
预先感谢,
Radhika.A.
Radhika.A.
推荐答案
这是一个简单的示例,没有多余的装饰.
Here is a simple example, no frills.
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add(new object[] { "Form2" });
dataGridView1.Rows.Add(new object[] { "Form3" });
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
OpenForm(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}
public static void OpenForm(string FormName)
{
var _formName = (from t in System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
where t.Name.Equals(FormName)
select t.FullName).Single();
var _form = (Form)Activator.CreateInstance(Type.GetType(_formName));
if (_form != null)
_form.Show();
}
}
}
或者
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add(new object[] { "AAA" });
dataGridView1.Rows.Add(new object[] { "BBB" });
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var f = new Form();
if (e.ColumnIndex == 0)
{
switch (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString())
{
case "AAA":
f = new Form2();
break;
case "BBB":
f = new Form3();
break;
}
f.Show();
}
}
}
}
这篇关于通过单击链接,我想打开其他链接的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文