pass dictionary to new form c#

251 views Asked by At

In my main form I create a new form:

private void buttonCreatePositionForm_Click(object sender, EventArgs e)
{ 
 f3 = new FormPosition(textBoxFiltermachineid.Text, textBoxFilterPositionFile.Text);
 f3.Show();
}

I also use a dictionary that is filled using the main form:

Dictionary<String, List<Reorder>> reorderPerFilename = new Dictionary<string, List<Reorder>>();

class Reorder
        {
            public int reordernumber { get; set; }
            public string reordervalue { get; set; }
            public int reorder0 { get; set; }
            public int reorder1 { get; set; }
            public int reorder2 { get; set; }
            public int reorder3 { get; set; }
            public int reorder4 { get; set; }
            public int reorder5 { get; set; }
            public int reorder6 { get; set; }
        }

Now I want to pass this dictionary with its content to the new form so the values can be used:

        public FormPosition(string machineId, string reorderCondition)
        {
            InitializeComponent();

            if (!string.IsNullOrWhiteSpace(machineId) && !string.IsNullOrWhiteSpace(reorderCondition))
            {
                labelMachineId.Text = machineId;
                labelReorderCondition.Text = reorderCondition;     
            }  
        }

I continuesly get errors

Error 4 Argument 1: cannot convert from 'System.Collections.Generic.Dictionary>' to 'System.Collections.Generic.Dictionary>'

when trying this:

private void buttonCreatePositionForm_Click(object sender, EventArgs e)
        {
            f3 = new FormPosition(reorderPerFilename, textBoxFiltermachineid.Text, textBoxFilterPositionFile.Text);
            f3.Show();
        }

class Reorder2
        {
            public int reordernumber { get; set; }
            public string reordervalue { get; set; }
            public int reorder0 { get; set; }
            public int reorder1 { get; set; }
            public int reorder2 { get; set; }
            public int reorder3 { get; set; }
            public int reorder4 { get; set; }
            public int reorder5 { get; set; }
            public int reorder6 { get; set; }
        }

        public FormPosition(Dictionary<String, List<Reorder2>> reorderPerFilename, string machineId, string reorderCondition)
        {
            InitializeComponent();

            if (!string.IsNullOrWhiteSpace(machineId) && !string.IsNullOrWhiteSpace(reorderCondition))
            {
                labelMachineId.Text = machineId;
                labelReorderCondition.Text = reorderCondition;     
            }  
        }

What am I doing wrong here?

1

There are 1 answers

0
Henk Nies On

you can add a property to person class. But it should be static property.

Static properties can be accessed without creating an instance.

They created when your application starts and they live till your application closes