jeudi 4 janvier 2018

C# Json fill textbox based on combobox selected value

I have the following situation: I am working on a windows form with a combobox, a checkbox, a button and a text box.

I have the following json:

{
"SDEOptions": [
    {
        "name": "Option 1",
        "attributes": [
            {
                "description": "some text here",
                "otherDescription": "more complex here if checkbox is checked",
                "question": "Checkbox checked?"
            }
        ]
    },
    {
        "name": "Option 2",
        "attributes": [
            {
                "description": "some text here",
                "otherDescription": "more complex here if checkbox is checked",
                "question": "Checkbox checked?"
            }
        ]
    }
]}

I would like to display the description or otherDescription property (if checkbox is checked) for the specific Option selected in the combobox.

For now I have managed to fill the combobox with the name properties from JSON like so:

            var rootObj = SdeOptions.FromJson(File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Data\\Options.json")));
            if (rootObj == null) return;
            foreach (var name in rootObj.SDEOptions)
            {
                boxOptions.Items.Add(name.name);

            }
            boxOptions.Sorted = true;

Just started to lean c# and Json, and to be honest I really do not know if this is the correct json format I should use.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire