TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Divya
NA
14
3.1k
drag and drop data from listbox to datagridview
Oct 31 2015 6:52 AM
hi c# coder
this is my project.
I need to drag some items in listbox box and drop it to the datagridview Name column. but the default name would not be change at any cost.
but i need to get the message box of that particular row which i drop the item . in that row Present details are shown into messageBox.
my coding is.
I connect my datagridview and listbox in to database.
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(string)))
{
string item = (string)e.Data.GetData(typeof(System.String));
Point clientPoint = dataGridView1.PointToClient(new Point(e.X, e.Y));
DataGridView.HitTestInfo info = dataGridView1.HitTest(clientPoint.X, clientPoint.Y);
if (info.Type == DataGridViewHitTestType.Cell)
{
if (dataGridView1.Columns[info.ColumnIndex].HeaderText == "Name")
dataGridView1.Rows[info.RowIndex].Cells[info.ColumnIndex].Value = item;
MessageBox.Show("data is " + item);
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
listBox1.DoDragDrop(listBox1.SelectedItem, DragDropEffects.Copy);
}
And my output is:
for this i drag 106 into listbox drop it to the datagridview name table. the name value is change to 106 and messagebox contain 106. i no need this kind
when i drop the item into name column i name did not to be change and i get that droped row present details into messageBox
i tried lot but did not get
Please help me. :-(
Reply
Answers (
1
)
whitelist sites/url for web browsers like crome
export data datagridview to textfile in windowsforms