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
The DataGridView control supports the standard Windows Forms data binding model, so it can bind to a variety of data sources. Usually, you bind to a BindingSource that manages the interaction with the data source.
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);
}
DataGridViewLinkColumn
looks promising.
DataGridViewLinkColumn
DataGridViewLinkColumn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With