【发布时间】:2015-02-19 02:28:39
【问题描述】:
我一直在使用其他人在线提供的代码,但由于某种原因,它不允许我将项目从 datagridview 拖动到文本框。我突出显示 dataGridView 中的一行并尝试将其拖到文本框,但没有任何反应。我还为 textBox 启用了 drop 属性,但仍然没有区别。这是我正在使用的代码:
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
if (info.RowIndex >= 0 && info.ColumnIndex >= 0)
{
string text = (String)
dataGridView1.Rows[info.RowIndex].Cells[info.ColumnIndex].Value;
if (text != null)
dataGridView1.DoDragDrop(text, DragDropEffects.Copy);
}
}
}
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
{
textBox1.Text = (System.String)e.Data.GetData(typeof(System.String));
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
【问题讨论】:
-
这是在桌面应用还是网络应用上?
标签: c# datagridview drag-and-drop