hi !
who know give any item from listview to gridview when we double click on listview ? please help me! ^^
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Oct 17, 2009, 7:08 AM EDT
1.on the listview add an event for row_click
2.take the selectedItem.value
and add it to the datatable that is bounded to the gridview
3. call datatable.syncchanges in order to update the changes to the gridview
and thats it :-)
if you are nto bounded to a datatable you can also just call
datagridView.Rows.add(new datagridViewRow());
and on the new row add the item selectedvalue
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 17, 2009, 9:45 AM EDT
dont forget to mark "do you like this answer" please if my answer helped you :)
private void Form1_Load(object sender, EventArgs e)
{
listView1.FullRowSelect = true;
//Just Filling Sample Data in ListView
string[] items = new string[2];
items[0] = "Test";
items[1] = "Coolumn2";
for (int i = 0; i <= 10; i++)
{
ListViewItem lvi = new ListViewItem(items);
listView1.Items.Add(lvi);
}
}
//Transfer All rows From ListView to DataGridView
private void btnTransfer_Click(object sender, EventArgs e)
{
//Code For Trasfering All the Rows
int lastrow;
foreach (ListViewItem lvi in listView1.Items)
{
dataGridView1.Rows.Add();
lastrow = dataGridView1.Rows.Count - 2;
dataGridView1.Rows[lastrow].Cells[0].Value = lvi.SubItems[0].Text;
dataGridView1.Rows[lastrow].Cells[1].Value = lvi.SubItems[1].Text;
}
//if you want to Trasfering Just Selected row to the DataGridView Uncomment This Code
//and Commentout Above code
//dataGridView1.Rows.Add();
//int lastrow1 = dataGridView1.Rows.Count - 2;
//dataGridView1.Rows[lastrow1].Cells[0].Value = listView1.SelectedItems[0].SubItems[0].Text;
//dataGridView1.Rows[lastrow1].Cells[1].Value = listView1.SelectedItems[0].SubItems[0].Text;
}