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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Oct 17, 2009, 1:45 PM
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;
}
Roei BarPosted Oct 17, 2009, 11:08 AM
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