Assign a value to combobox depend upon other combobox value











up vote
2
down vote

favorite












I have a windows form in C# project that keeps some information. I created a bunch of textbox and combobox dynamically, depend upon user input.



Consider, I have a list of 10 combobox whose values will be selected by user.



The combobox values are:




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped.


Now I have a single final combobox which contains the following values.




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped Reviewed

  5. Skipped Not reviewed


The final combobox should be populated depend upon the following logic




  1. If all values are "Finding", then the the final combobox should be "Finding"

  2. If all values are "No_Finding", then the the final combobox should be "No_Finding"

  3. If all values are "InComplete", then the the final combobox should be "InComplete"

  4. If all values are "Skipped", then the the final combobox should be "Skipped Not Reviewed".


  5. If any value is "Finding", then the final combobox should be "Finding".


  6. If any value is "Incomplete", then the final combobox should be "Incomplete".

  7. If any value is "Skipped", then the final combobox should be "Skipped Reviewed".


With respect to the above logic conditions I have written the following that works fine.



After writing the code I feel it's not cleaner and not an easily understandable solution.



What I need now whether there is any way to refactor the following lines of code.



 public void selectfinalComboxValue()
{
List<string> list_of_combobox = new List<string>();
//txtBoxValLines is an user input
for (int i = 0; i < int.Parse(txtboxvalLines.Text); i++)
{
string cmbboxValue = ((ComboBox)panel1.Controls["Add_combobox" + (i).ToString()]).Text;
list_of_combobox.Add(cmbboxValue);

}
List<string> distinct = list_of_combobox.Distinct().ToList();

if (distinct.Any(str => str.Contains("InComplete")))
{
cmbFinalStatus.SelectedIndex = 2;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("Finding")))
{
cmbFinalStatus.SelectedIndex = 0;
cmbFinalStatus.Enabled = false;
}
else
{
cmbFinalStatus.SelectedIndex = -1;
cmbFinalStatus.Enabled = true;
}

if (distinct.Count().ToString() == "1")
{

if (distinct.Any(str => str.Equals("Skipped")))
{
cmbFinalStatus.SelectedIndex = 4;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("No Finding")))
{
cmbFinalStatus.SelectedIndex = 1;
cmbFinalStatus.Enabled = false;
}
}
else {
if (distinct.Any(str => str.Contains("Skipped")))
{
cmbFinalStatus.SelectedIndex = 3;
cmbFinalStatus.Enabled = false;
}

}
}









share|improve this question
























  • What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
    – Calak
    2 days ago










  • @Calak In that case it is Incomplete.
    – Vini
    2 days ago












  • edited my code below, too show you more :)
    – Calak
    15 hours ago















up vote
2
down vote

favorite












I have a windows form in C# project that keeps some information. I created a bunch of textbox and combobox dynamically, depend upon user input.



Consider, I have a list of 10 combobox whose values will be selected by user.



The combobox values are:




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped.


Now I have a single final combobox which contains the following values.




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped Reviewed

  5. Skipped Not reviewed


The final combobox should be populated depend upon the following logic




  1. If all values are "Finding", then the the final combobox should be "Finding"

  2. If all values are "No_Finding", then the the final combobox should be "No_Finding"

  3. If all values are "InComplete", then the the final combobox should be "InComplete"

  4. If all values are "Skipped", then the the final combobox should be "Skipped Not Reviewed".


  5. If any value is "Finding", then the final combobox should be "Finding".


  6. If any value is "Incomplete", then the final combobox should be "Incomplete".

  7. If any value is "Skipped", then the final combobox should be "Skipped Reviewed".


With respect to the above logic conditions I have written the following that works fine.



After writing the code I feel it's not cleaner and not an easily understandable solution.



What I need now whether there is any way to refactor the following lines of code.



 public void selectfinalComboxValue()
{
List<string> list_of_combobox = new List<string>();
//txtBoxValLines is an user input
for (int i = 0; i < int.Parse(txtboxvalLines.Text); i++)
{
string cmbboxValue = ((ComboBox)panel1.Controls["Add_combobox" + (i).ToString()]).Text;
list_of_combobox.Add(cmbboxValue);

}
List<string> distinct = list_of_combobox.Distinct().ToList();

if (distinct.Any(str => str.Contains("InComplete")))
{
cmbFinalStatus.SelectedIndex = 2;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("Finding")))
{
cmbFinalStatus.SelectedIndex = 0;
cmbFinalStatus.Enabled = false;
}
else
{
cmbFinalStatus.SelectedIndex = -1;
cmbFinalStatus.Enabled = true;
}

if (distinct.Count().ToString() == "1")
{

if (distinct.Any(str => str.Equals("Skipped")))
{
cmbFinalStatus.SelectedIndex = 4;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("No Finding")))
{
cmbFinalStatus.SelectedIndex = 1;
cmbFinalStatus.Enabled = false;
}
}
else {
if (distinct.Any(str => str.Contains("Skipped")))
{
cmbFinalStatus.SelectedIndex = 3;
cmbFinalStatus.Enabled = false;
}

}
}









share|improve this question
























  • What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
    – Calak
    2 days ago










  • @Calak In that case it is Incomplete.
    – Vini
    2 days ago












  • edited my code below, too show you more :)
    – Calak
    15 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a windows form in C# project that keeps some information. I created a bunch of textbox and combobox dynamically, depend upon user input.



Consider, I have a list of 10 combobox whose values will be selected by user.



The combobox values are:




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped.


Now I have a single final combobox which contains the following values.




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped Reviewed

  5. Skipped Not reviewed


The final combobox should be populated depend upon the following logic




  1. If all values are "Finding", then the the final combobox should be "Finding"

  2. If all values are "No_Finding", then the the final combobox should be "No_Finding"

  3. If all values are "InComplete", then the the final combobox should be "InComplete"

  4. If all values are "Skipped", then the the final combobox should be "Skipped Not Reviewed".


  5. If any value is "Finding", then the final combobox should be "Finding".


  6. If any value is "Incomplete", then the final combobox should be "Incomplete".

  7. If any value is "Skipped", then the final combobox should be "Skipped Reviewed".


With respect to the above logic conditions I have written the following that works fine.



After writing the code I feel it's not cleaner and not an easily understandable solution.



What I need now whether there is any way to refactor the following lines of code.



 public void selectfinalComboxValue()
{
List<string> list_of_combobox = new List<string>();
//txtBoxValLines is an user input
for (int i = 0; i < int.Parse(txtboxvalLines.Text); i++)
{
string cmbboxValue = ((ComboBox)panel1.Controls["Add_combobox" + (i).ToString()]).Text;
list_of_combobox.Add(cmbboxValue);

}
List<string> distinct = list_of_combobox.Distinct().ToList();

if (distinct.Any(str => str.Contains("InComplete")))
{
cmbFinalStatus.SelectedIndex = 2;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("Finding")))
{
cmbFinalStatus.SelectedIndex = 0;
cmbFinalStatus.Enabled = false;
}
else
{
cmbFinalStatus.SelectedIndex = -1;
cmbFinalStatus.Enabled = true;
}

if (distinct.Count().ToString() == "1")
{

if (distinct.Any(str => str.Equals("Skipped")))
{
cmbFinalStatus.SelectedIndex = 4;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("No Finding")))
{
cmbFinalStatus.SelectedIndex = 1;
cmbFinalStatus.Enabled = false;
}
}
else {
if (distinct.Any(str => str.Contains("Skipped")))
{
cmbFinalStatus.SelectedIndex = 3;
cmbFinalStatus.Enabled = false;
}

}
}









share|improve this question















I have a windows form in C# project that keeps some information. I created a bunch of textbox and combobox dynamically, depend upon user input.



Consider, I have a list of 10 combobox whose values will be selected by user.



The combobox values are:




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped.


Now I have a single final combobox which contains the following values.




  1. Finding

  2. No Finding

  3. Incomplete

  4. Skipped Reviewed

  5. Skipped Not reviewed


The final combobox should be populated depend upon the following logic




  1. If all values are "Finding", then the the final combobox should be "Finding"

  2. If all values are "No_Finding", then the the final combobox should be "No_Finding"

  3. If all values are "InComplete", then the the final combobox should be "InComplete"

  4. If all values are "Skipped", then the the final combobox should be "Skipped Not Reviewed".


  5. If any value is "Finding", then the final combobox should be "Finding".


  6. If any value is "Incomplete", then the final combobox should be "Incomplete".

  7. If any value is "Skipped", then the final combobox should be "Skipped Reviewed".


With respect to the above logic conditions I have written the following that works fine.



After writing the code I feel it's not cleaner and not an easily understandable solution.



What I need now whether there is any way to refactor the following lines of code.



 public void selectfinalComboxValue()
{
List<string> list_of_combobox = new List<string>();
//txtBoxValLines is an user input
for (int i = 0; i < int.Parse(txtboxvalLines.Text); i++)
{
string cmbboxValue = ((ComboBox)panel1.Controls["Add_combobox" + (i).ToString()]).Text;
list_of_combobox.Add(cmbboxValue);

}
List<string> distinct = list_of_combobox.Distinct().ToList();

if (distinct.Any(str => str.Contains("InComplete")))
{
cmbFinalStatus.SelectedIndex = 2;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("Finding")))
{
cmbFinalStatus.SelectedIndex = 0;
cmbFinalStatus.Enabled = false;
}
else
{
cmbFinalStatus.SelectedIndex = -1;
cmbFinalStatus.Enabled = true;
}

if (distinct.Count().ToString() == "1")
{

if (distinct.Any(str => str.Equals("Skipped")))
{
cmbFinalStatus.SelectedIndex = 4;
cmbFinalStatus.Enabled = false;
}
else if (distinct.Any(str => str.Equals("No Finding")))
{
cmbFinalStatus.SelectedIndex = 1;
cmbFinalStatus.Enabled = false;
}
}
else {
if (distinct.Any(str => str.Contains("Skipped")))
{
cmbFinalStatus.SelectedIndex = 3;
cmbFinalStatus.Enabled = false;
}

}
}






c# winforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Calak

1,799214




1,799214










asked 2 days ago









Vini

183




183












  • What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
    – Calak
    2 days ago










  • @Calak In that case it is Incomplete.
    – Vini
    2 days ago












  • edited my code below, too show you more :)
    – Calak
    15 hours ago


















  • What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
    – Calak
    2 days ago










  • @Calak In that case it is Incomplete.
    – Vini
    2 days ago












  • edited my code below, too show you more :)
    – Calak
    15 hours ago
















What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
– Calak
2 days ago




What happens if list_of_combobox have 5 Finding and 5 Incomplete ?
– Calak
2 days ago












@Calak In that case it is Incomplete.
– Vini
2 days ago






@Calak In that case it is Incomplete.
– Vini
2 days ago














edited my code below, too show you more :)
– Calak
15 hours ago




edited my code below, too show you more :)
– Calak
15 hours ago










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










I won't give you the full response, because your code lack of context (we didn't know nothing about cmbFinalStatus...).



Without using distinct



result value is set if case case 1,2,3,4 match.



List<string> all_of = new List<string>(){"Skipped", "Incomplete", "No_Finding", "Finding"};
var result = all_of.FirstOrDefault(lhs => list_of_combobox.All(rhs => rhs.Equals(lhs)));
if (


result value is set if case 5,6,7 match.



List<string> first_of = new List<string>(){"Skipped", "Incomplete", "Finding"};
var result = first_of.FirstOrDefault(lhs => list_of_combobox.Any(rhs => rhs.Equals(lhs)));


Edit: Putting all together, we got:



  // for... populating list_of_combobox
// ...

var str = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped"}
.Where(lhs => list_of_combobox.All(rhs => lhs.Equals(rhs)))
.FirstOrDefault() ?? string.Empty;

if (str.Length != 0)
{
if (str.Equals("Skipped")) str = "Skipped Not Reviewed";
}
else
{
str = new List<string>(){"Finding", "InComplete", "Skipped"}
.Where(lhs => list_of_combobox.Any(rhs => lhs.Equals(rhs)))
.FirstOrDefault() ?? string.Empty;

if (str.Equals("Skipped")) str = "Skipped Reviewed";
}

cmbFinalStatus.SelectedIndex = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped Reviewed", "Skipped Not Reviewed"}
.IndexOf(str);

cmbFinalStatus.Enabled = (cmbFinalStatus.SelectedIndex < 0);





share|improve this answer























  • Awesome work. Thank you.
    – Vini
    13 hours ago




















up vote
1
down vote













I think you might be able to eliminate creating the distinct list and the nested ifs by first checking for the All() condtions, then later check for Any()



    var items = list_of_combobox.ToList();

if (items.All(str => str.Equals("Finding")))
{
// assign final comboxbox
}
else if (items.Any(str => str.Equals("Finding")))


Also, you might want to try creating an enum of the possible values, adding these values to the ComboBox, then getting/setting the SelectedItem property rather than dealing with indexes.






share|improve this answer





















    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "196"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208151%2fassign-a-value-to-combobox-depend-upon-other-combobox-value%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    I won't give you the full response, because your code lack of context (we didn't know nothing about cmbFinalStatus...).



    Without using distinct



    result value is set if case case 1,2,3,4 match.



    List<string> all_of = new List<string>(){"Skipped", "Incomplete", "No_Finding", "Finding"};
    var result = all_of.FirstOrDefault(lhs => list_of_combobox.All(rhs => rhs.Equals(lhs)));
    if (


    result value is set if case 5,6,7 match.



    List<string> first_of = new List<string>(){"Skipped", "Incomplete", "Finding"};
    var result = first_of.FirstOrDefault(lhs => list_of_combobox.Any(rhs => rhs.Equals(lhs)));


    Edit: Putting all together, we got:



      // for... populating list_of_combobox
    // ...

    var str = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.All(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Length != 0)
    {
    if (str.Equals("Skipped")) str = "Skipped Not Reviewed";
    }
    else
    {
    str = new List<string>(){"Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.Any(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Equals("Skipped")) str = "Skipped Reviewed";
    }

    cmbFinalStatus.SelectedIndex = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped Reviewed", "Skipped Not Reviewed"}
    .IndexOf(str);

    cmbFinalStatus.Enabled = (cmbFinalStatus.SelectedIndex < 0);





    share|improve this answer























    • Awesome work. Thank you.
      – Vini
      13 hours ago

















    up vote
    1
    down vote



    accepted










    I won't give you the full response, because your code lack of context (we didn't know nothing about cmbFinalStatus...).



    Without using distinct



    result value is set if case case 1,2,3,4 match.



    List<string> all_of = new List<string>(){"Skipped", "Incomplete", "No_Finding", "Finding"};
    var result = all_of.FirstOrDefault(lhs => list_of_combobox.All(rhs => rhs.Equals(lhs)));
    if (


    result value is set if case 5,6,7 match.



    List<string> first_of = new List<string>(){"Skipped", "Incomplete", "Finding"};
    var result = first_of.FirstOrDefault(lhs => list_of_combobox.Any(rhs => rhs.Equals(lhs)));


    Edit: Putting all together, we got:



      // for... populating list_of_combobox
    // ...

    var str = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.All(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Length != 0)
    {
    if (str.Equals("Skipped")) str = "Skipped Not Reviewed";
    }
    else
    {
    str = new List<string>(){"Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.Any(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Equals("Skipped")) str = "Skipped Reviewed";
    }

    cmbFinalStatus.SelectedIndex = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped Reviewed", "Skipped Not Reviewed"}
    .IndexOf(str);

    cmbFinalStatus.Enabled = (cmbFinalStatus.SelectedIndex < 0);





    share|improve this answer























    • Awesome work. Thank you.
      – Vini
      13 hours ago















    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    I won't give you the full response, because your code lack of context (we didn't know nothing about cmbFinalStatus...).



    Without using distinct



    result value is set if case case 1,2,3,4 match.



    List<string> all_of = new List<string>(){"Skipped", "Incomplete", "No_Finding", "Finding"};
    var result = all_of.FirstOrDefault(lhs => list_of_combobox.All(rhs => rhs.Equals(lhs)));
    if (


    result value is set if case 5,6,7 match.



    List<string> first_of = new List<string>(){"Skipped", "Incomplete", "Finding"};
    var result = first_of.FirstOrDefault(lhs => list_of_combobox.Any(rhs => rhs.Equals(lhs)));


    Edit: Putting all together, we got:



      // for... populating list_of_combobox
    // ...

    var str = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.All(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Length != 0)
    {
    if (str.Equals("Skipped")) str = "Skipped Not Reviewed";
    }
    else
    {
    str = new List<string>(){"Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.Any(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Equals("Skipped")) str = "Skipped Reviewed";
    }

    cmbFinalStatus.SelectedIndex = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped Reviewed", "Skipped Not Reviewed"}
    .IndexOf(str);

    cmbFinalStatus.Enabled = (cmbFinalStatus.SelectedIndex < 0);





    share|improve this answer














    I won't give you the full response, because your code lack of context (we didn't know nothing about cmbFinalStatus...).



    Without using distinct



    result value is set if case case 1,2,3,4 match.



    List<string> all_of = new List<string>(){"Skipped", "Incomplete", "No_Finding", "Finding"};
    var result = all_of.FirstOrDefault(lhs => list_of_combobox.All(rhs => rhs.Equals(lhs)));
    if (


    result value is set if case 5,6,7 match.



    List<string> first_of = new List<string>(){"Skipped", "Incomplete", "Finding"};
    var result = first_of.FirstOrDefault(lhs => list_of_combobox.Any(rhs => rhs.Equals(lhs)));


    Edit: Putting all together, we got:



      // for... populating list_of_combobox
    // ...

    var str = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.All(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Length != 0)
    {
    if (str.Equals("Skipped")) str = "Skipped Not Reviewed";
    }
    else
    {
    str = new List<string>(){"Finding", "InComplete", "Skipped"}
    .Where(lhs => list_of_combobox.Any(rhs => lhs.Equals(rhs)))
    .FirstOrDefault() ?? string.Empty;

    if (str.Equals("Skipped")) str = "Skipped Reviewed";
    }

    cmbFinalStatus.SelectedIndex = new List<string>(){"Finding", "No Finding", "InComplete", "Skipped Reviewed", "Skipped Not Reviewed"}
    .IndexOf(str);

    cmbFinalStatus.Enabled = (cmbFinalStatus.SelectedIndex < 0);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 15 hours ago

























    answered 2 days ago









    Calak

    1,799214




    1,799214












    • Awesome work. Thank you.
      – Vini
      13 hours ago




















    • Awesome work. Thank you.
      – Vini
      13 hours ago


















    Awesome work. Thank you.
    – Vini
    13 hours ago






    Awesome work. Thank you.
    – Vini
    13 hours ago














    up vote
    1
    down vote













    I think you might be able to eliminate creating the distinct list and the nested ifs by first checking for the All() condtions, then later check for Any()



        var items = list_of_combobox.ToList();

    if (items.All(str => str.Equals("Finding")))
    {
    // assign final comboxbox
    }
    else if (items.Any(str => str.Equals("Finding")))


    Also, you might want to try creating an enum of the possible values, adding these values to the ComboBox, then getting/setting the SelectedItem property rather than dealing with indexes.






    share|improve this answer

























      up vote
      1
      down vote













      I think you might be able to eliminate creating the distinct list and the nested ifs by first checking for the All() condtions, then later check for Any()



          var items = list_of_combobox.ToList();

      if (items.All(str => str.Equals("Finding")))
      {
      // assign final comboxbox
      }
      else if (items.Any(str => str.Equals("Finding")))


      Also, you might want to try creating an enum of the possible values, adding these values to the ComboBox, then getting/setting the SelectedItem property rather than dealing with indexes.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        I think you might be able to eliminate creating the distinct list and the nested ifs by first checking for the All() condtions, then later check for Any()



            var items = list_of_combobox.ToList();

        if (items.All(str => str.Equals("Finding")))
        {
        // assign final comboxbox
        }
        else if (items.Any(str => str.Equals("Finding")))


        Also, you might want to try creating an enum of the possible values, adding these values to the ComboBox, then getting/setting the SelectedItem property rather than dealing with indexes.






        share|improve this answer












        I think you might be able to eliminate creating the distinct list and the nested ifs by first checking for the All() condtions, then later check for Any()



            var items = list_of_combobox.ToList();

        if (items.All(str => str.Equals("Finding")))
        {
        // assign final comboxbox
        }
        else if (items.Any(str => str.Equals("Finding")))


        Also, you might want to try creating an enum of the possible values, adding these values to the ComboBox, then getting/setting the SelectedItem property rather than dealing with indexes.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        C.M.

        1173




        1173






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208151%2fassign-a-value-to-combobox-depend-upon-other-combobox-value%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Quarter-circle Tiles

            build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

            Mont Emei