【发布时间】:2014-10-27 13:26:24
【问题描述】:
textbox1.text = 123 ;
textbox2.text = examples ;
我在listbox1中的两个文本框值上方添加了列表框
在listbox = 123 examples添加like show后
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
Point clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
DataGridView.HitTestInfo hti = dataGridView1.HitTest(clientPoint.X, clientPoint.Y);
DataGridViewCell targetCell = dataGridView1[hti.ColumnIndex, hti.RowIndex];
if (targetCell.Value == null)
{
targetCell.Value = e.Data.GetData(DataFormats.Text);
}
else
{
if (targetCell.Value.ToString().Contains(e.Data.GetData(DataFormats.Text).ToString().Split(' ')[1]))
{
}
else
{
targetCell.Value = targetCell.Value.ToString().Split(' ')[1] + System.Environment.NewLine + e.Data.GetData(DataFormats.Text);
}
}
textBox3.Text = e.Data.GetData("System.String").ToString().Split()[0];
}
现在,如果我将列表框项(123 个示例)中的任何单元格拖放到我的 datagridview 中,它应该像 textbox3.text = 123;以及 datagridview 单元格的示例。
上面的代码使用但它的拆分但没有解决。
视觉示例:
【问题讨论】:
-
将“文本”添加到文本框的方式不起作用。您需要将它们放在引号中,例如
textbox2.text = "examples"; -
是的,我已经加了引号,但是拖放后给我们带来了问题。
-
你的代码的输出是什么?
-
输出是“123”在textbox3中,“123 sometext”在datagridview单元格中,表示123在两者中重复。
标签: c# datagridview drag-and-drop