Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i used 4 textboxes and datagridview have 5 columns and 4 rows
and listbox have items like below
123 test one1
124 test two2
125 test three3
126 test four4 


i want if i drag form listbox item (123 test one1) to datagridview it should be split value is like "123" is in textbox1 and "test one1" is in datagridview 1st column and 1st row and also select another item (124 test two2) to datagridview then it should be split "124" is textbox2 and "test one2" is 1st column 2nd row.

below this is my code but its not my what i need.plz check code and advise me the correction.
C#
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];

    targetCell.Value = e.Data.GetData(DataFormats.Text).ToString().Split(' ')[1];   //for GridCell

    textBox1.Text = e.Data.GetData("System.String").ToString().Split()[0];  //for TextBox
}
Posted
Updated 29-Oct-14 9:37am
v2
Comments
j snooze 29-Oct-14 17:25pm    
You haven't told us what its doing thats incorrect. You have to describe what it's doing thats wrong, we can't see it from your code snippet. My only guess is based on your description that you need to concatenate split(' ')[1] and split(' ')[2] to get the second 2 words in your grid cell, and for your textbox you are missing the character to split by (the ' ').

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900