You can just capture the click event and use the contents of the column to open your web address
如果您的表格各有三栏,每栏有一栏。
DataTable dataTable = new DataTable();
dataTable.Columns.Add("Website1", typeof(String));
dataTable.Columns.Add("Website2", typeof(String));
dataTable.Columns.Add("Website3", typeof(String));
DataRow dr = dataTable.NewRow();
dr["Website1"] = "http://www.bbc.co.uk";
dr["Website2"] = "http://www.ebay.co.uk";
dr["Website3"] = "http://www.google.co.uk";
dataTable.Rows.Add(dr);
dataGrid1.DataSource = dataTable;
然后,你可以把这作为超级链接。
private void dataGrid1_Click(object sender, EventArgs e)
{
int rowNumber = dataGrid1.CurrentCell.RowNumber;
int columnNumber = dataGrid1.CurrentCell.ColumnNumber;
System.Diagnostics.Process.Start("iexplore.exe",
dgSites[rowNumber, columnNumber].ToString());
}
如果你只想用一个栏子来启动你的联系,那么仅仅通过核对栏号来考虑这一点。
private void dataGrid1_Click(object sender, EventArgs e)
{
int rowNumber = dataGrid1.CurrentCell.RowNumber;
int columnNumber = dataGrid1.CurrentCell.ColumnNumber;
if (columnNumber == 2)
{
System.Diagnostics.Process.Start("iexplore.exe",
dgSites[rowNumber, columnNumber].ToString());
}
}
问题完全是要你努力做到,但是,如果你只是想在信息箱中显示该项目,那就不清楚。
private void dataGrid1_Click(object sender, EventArgs e)
{
int rowNumber = dataGrid1.CurrentCell.RowNumber;
int columnNumber = dataGrid1.CurrentCell.ColumnNumber;
if (columnNumber == 2)
{
MessageBox.Show(dgSites[rowNumber, columnNumber].ToString());
}
}