jkm_22

Hi
I have a windows application coded using Visual C# in .NET 2005.
The application queries data stored in an MS Access table. One of the field in the access table contains text which is hyperlinked to particular files on the local machine.
Say, I have a field called TITLE and all each of the specific documents (pdf or word) are hyperlinked to the corresponding record in the TITLE field.
I am able to do this in Acess.
But, this property does not carry over in the windows application.
I am using a datagrid to display the queried results.
I set the required field to be as "Hyperlink" property for the datagrid and still the file does not open.
Any ideas on how to fix this



Re: Windows Forms Data Controls and Databinding Hyperlink in Datagrids

Ken_L

You have to make an event in the particular cell/column that houses the hyperlink.

In the example the mouse click is checked to to ensure left click. Then it checks to make sure the left click happened in the correct column. Then the data in that cell is passed to a method that opens the file.

Code Snippet

private void dataGridView1_MouseClick(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

{

LeftClick();

}

}

private void LeftClick()

{

if (this.dataGridView1.CurrentCellAddress.X == 6) // 6 being the hyperlink column

{

// Open Document

OpenSelectedDoc(

this.dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["ColumnName"].Value.ToString().Trim());

}

}

private void OpenSelectedDoc(string FullPath)

{

System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents = false;

proc.StartInfo.FileName = FullPath;

proc.Start();

}