CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Location
    United States Of America
    Posts
    21

    Question drag text from Datagridview to richtextbox

    I am trying to drag from datagridview and drop in richtextbox.
    Can anyone throw expertise on what is wrong with the following code?

    Code:
    public void dataGridView1_MouseDown(object sender, MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Left)
    {
    DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);
    if (info.RowIndex >= 0)
    {
    DataRowView view = (DataRowView)
    dataGridView1.Rows[info.RowIndex].DataBoundItem;
    if (view != null)
    dataGridView1.DoDragDrop(view, DragDropEffects.Copy);
    }
    }
    }
    
    public void richTextBox1_DragDrop(object sender, DragEventArgs e)
    {
    // Get Start Position to Drop the Text 
    int i = richTextBox1.SelectionStart;
    String s = richTextBox1.Text.Substring(i);
    richTextBox1.Text = richTextBox1.Text.Substring(0, i);
    
    if (e.Data.GetDataPresent(typeof(System.String)))
    {
    richTextBox1.Text = richTextBox1.Text + (System.String)e.Data.GetData(typeof(System.String));
    }
    richTextBox1.Text = richTextBox1.Text + s;
    
    }
    Yes, Possible!!

  2. #2
    Join Date
    Apr 2008
    Location
    United States Of America
    Posts
    21

    Cool Re: drag text from Datagridview to richtextbox

    Ok, let me be more clear..

    i have used MouseDrop event for datagridview, and dragdrop and dragenter events for richtextbox here.
    The code works for draging text from Microsoft Wordpad. But it does not for the text i try to drag from the datagridView..

    Is it a compatibility issue between richtextbox and datagridview??

    Where the experts are ??
    Yes, Possible!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured