且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ListBox项目复制到datagridview

更新时间:2022-10-22 23:36:23

您***的选择始终是更新数据源并重新绑定,而不是在控件之间移动数据.


>

i have a listbox and a datagridview. When I double click an item of the listbox, then I want to copy it to specific column cells of the datagridview. For example if i select from listbox the item "cd", then the cell (of specific column) to be update with the cd value. (listbox is not connect to the database)

If anyone knows to help me please..



I get the selected item from listbox...

private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            string item;
            item = listBox1.SelectedItem.ToString();
            MessageBox.Show("Selected Index = " + item);
        }



Then i am thinking to get the datagridview cell that my mouse is an copy it there..

What do you think.

Thanks!

Your best bet is always to update the data source and rebind, not to move data between the controls.