Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#动态对象表listbox-listbox1和动态listbox之间的dragdrop方法[n]_C#_Dynamic_Methods_Drag And Drop_Listbox - Fatal编程技术网

C#动态对象表listbox-listbox1和动态listbox之间的dragdrop方法[n]

C#动态对象表listbox-listbox1和动态listbox之间的dragdrop方法[n],c#,dynamic,methods,drag-and-drop,listbox,C#,Dynamic,Methods,Drag And Drop,Listbox,我对拖放效果有问题。我想将所选索引从ListBoxListAprzedMitow移动到动态分配的listboxA[n]。我没有任何想法来解决在动态对象上使用方法的问题。请帮忙 这是我的密码: namespace WindowsFormsApplication1 { public partial class Form1 : Form { static decimal kolumny = 3;//numericUpDownKolumny.Value;

我对拖放效果有问题。我想将所选索引从ListBoxListAprzedMitow移动到动态分配的listboxA[n]。我没有任何想法来解决在动态对象上使用方法的问题。请帮忙

这是我的密码:

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        static decimal kolumny = 3;//numericUpDownKolumny.Value;
        static decimal wiersze = 4;//numericUpDownWiersze.Value;
        static int n = (int)kolumny * (int)wiersze;
        ListBox[] listboxA = new ListBox[n];

        public Form1()
        {
            InitializeComponent();
        }
        public void AddNewListBox()
        {
            int i = 0;


            for (int y = 0; y < wiersze; y++)
            {
                for (int x = 0; x < kolumny; x++)
                {
                    //ListBox[] listboxA = new ListBox();
                    listboxA[i] = new ListBox();
                    listboxA[i].Left = 9 + 126 * x;
                    listboxA[i].Top = 64 + 101 * y;
                    splitContainer1.Panel2.Controls.Add(listboxA[i]);
                    listboxA[i].AllowDrop = true;
                    i++;

                }
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            AddNewListBox();     
        }
        private void listBoxListaPrzedmiotow_MouseDown(object sender, MouseEventArgs e)
        {
            listBoxListaPrzedmiotow.DoDragDrop(listBoxListaPrzedmiotow.SelectedIndex, DragDropEffects.Copy);
        }

        private void listBoxListaPrzedmiotow_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
                e.Effect = DragDropEffects.Copy;
            else
                e.Effect = DragDropEffects.None;

        }

        private void listBoxListaPrzedmiotow_DragDrop(object sender, DragEventArgs e)
        {
            listBoxListaPrzedmiotow.Items.Add(e.Data.GetData(DataFormats.Text));
        }

        private void listBoxA_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.All;
        }

        private void listBoxA_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                string str = (string)e.Data.GetData(
                    DataFormats.StringFormat);
                for (int i=0; i < n; i++)
                    listboxA[i].Items.Add(str);
            }
        }
    }
}
命名空间窗口窗体应用程序1
{
公共部分类Form1:Form
{
静态十进制kolumny=3;//numericUpDownKolumny.Value;
静态十进制wiersze=4;//numericUpDownWiersze.Value;
静态int n=(int)kolumny*(int)wiersze;
ListBox[]listboxA=新的ListBox[n];
公共表格1()
{
初始化组件();
}
public void AddNewListBox()
{
int i=0;
对于(int y=0;y