views:

118

answers:

3

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

+2  A: 

DataGridViewLinkColumn looks promising.

Zach Johnson
This is good. Works with .NET 2.0 and better.
BrianLy
A: 

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);
    }
Hany