首页 > 解决方案 > 为什么这个 DataGridView 单元格格式错误?

问题描述

我有一个 DataGridView,并且我有一些如下所示的列代码:

private void dataGridView2_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
  DataGridViewLinkCell cell = new DataGridViewLinkCell();
  cell.LinkColor = Color.Blue;
  cell.VisitedLinkColor = Color.Blue;

  foreach(DataGridViewRow r in dataGridView2.Rows)
  {
    r.Cells["url"] = cell;
  }
}

我也有一些看起来像这样的双击代码:

private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
  if (dataGridView2.Columns[dataGridView2.CurrentCell.ColumnIndex].HeaderText.Contains("URL"))
  {
    if (!String.IsNullOrWhiteSpace(dataGridView2.CurrentCell.EditedFormattedValue.ToString()))
    {
      System.Diagnostics.Process.Start("http://" + dataGridView2.CurrentCell.EditedFormattedValue);
    }
  }
}

现在,在本专栏中,我双击具有http://aweber.com内容的单元格。我的笔记本电脑将我带到我的浏览器,但出现一个页面,说它在查找文件时遇到问题。我查看浏览器的地址栏,找到 http//aweber.com(没有冒号)。

为什么要切除结肠?

标签: c#datagridview

解决方案


你可以试试这个

System.Diagnostics.Process.Start($"{dgv.CurrentCell.EditedFormattedValue}");

推荐阅读