超链接在DataGridView [英] HyperLinks In DataGridView
问题描述
我有一个文件路径数组(作为字符串),我想显示这些路径作为 DataGridView
中的链接,以便用户单击文件名时将打开该文件。
注意:我正在使用C#Winforms,而不是ASP.net
我想我有我的问题的答案
我添加了一个DataGridViewLinkColumn到DataGridView
现在下一步将数据填充到datagridview
,文件名将显示为链接:
private void button1_Click(object sender,EventArgs e)
{
string [] SS = new string [3];
SS [0] =C:\\test1.txt;
SS [1] =C:\\test2.txt; (int i = 0; i {
dataGridView1.Rows.Add(SS [i]);
}
dataGridView1.Refresh();
}
最后一步:
现在我要打开文件用户点击它
我将使用CellContentClick事件,此代码将实现:
private void dataGridView1_CellContentClick (object sender,DataGridViewCellEventArgs e)
{
string filepath =(string)dataGridView1.Rows [e.RowIndex] .Cells [0] .Value;
System.Diagnostics.Process.Start(filepath);
}
I am working on C# application which is like a small search engine. The user will enter a word and the program will return the files that contains this word.
I have an array of file paths (as strings) and I want to show these paths as links in a DataGridView
, so that when the user clicks the file name the file will be opened.
Note: I am working on C# Winforms, not ASP.net
I think I have The Answer of my question I added a DataGridViewLinkColumn to the DataGridView now the next step will fill the Data into the datagridview and the File names will appear like links:
private void button1_Click(object sender, EventArgs e)
{
string[] SS = new string[3];
SS[0] = "C:\\test1.txt";
SS[1] = "C:\\test2.txt";
for (int i = 0; i < SS.Length; i++)
{
dataGridView1.Rows.Add(SS[i]);
}
dataGridView1.Refresh();
}
The Last step : now I want to open the file when the user click it I will use the "CellContentClick" event and this code will achieve it:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string filepath= (string)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
System.Diagnostics.Process.Start(filepath);
}
这篇关于超链接在DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!