Код не достигает строк в коде, который должен - PullRequest
0 голосов
/ 07 января 2020

По какой-то причине мой код не достигает последних нескольких строк. Я добавил точку остановки и точку возврата в коде. Я не вижу ничего плохого в источнике данных, который я использую в этой строке, когда проверяю его в отладке. Кажется, код устанавливает значение и переходит обратно к вершине foreach l oop.

foreach (DataGridViewRow row in dataGridView1.Rows) {
                //We check if the user has already filled in some info
return point   if (row.Cells[7].Value != null && row.Cells[6].Value != null && !askedTheUser)
                {
                    //trigger for message if you want to replace them
                    Message m = new Message("There is already info present in the category and or size dropdown. Would you like to overwrite this?", "Overwrite", "YESNO");

                    if (m.Awnser) {
                        overwrite = true;
                    }
                    askedTheUser = true;
                }

                DataGridViewComboBoxCell cat = (DataGridViewComboBoxCell)row.Cells[6];
                string toMatch = row.Cells[3].Value.ToString();

                //Now we will start matching
                //First we try to match with the package ( if that is filled in )
                if (row.Cells[5].Value != null && (string)row.Cells[5].Value != "") {
                    toMatch = row.Cells[5].Value.ToString();
                    matchWithPackage = true;
                }

                Regex re = new Regex(@"([a-zA-Z]+)(\d+)");
                Match result = re.Match(toMatch);

                string alphaPart = result.Groups[1].Value;
                string numberPart = result.Groups[2].Value;

                Datagridview dgv = new Datagridview();

                if (numberPart.Length < 4) {
                    numberPart = numberPart.PadLeft(4, '0');
                }
#if DEBUG
                Console.WriteLine(numberPart);
#endif
                //Matching the category
                if (CHIP != null && CHIP.Contains(alphaPart))
                {
                    cat.Value = "CHIP";
                }
                else if (SOJ != null && SOJ.Contains(alphaPart))
                {
                    cat.Value = "SOJ";
                }
                else if (PLCC != null && PLCC.Contains(alphaPart))
                {
                    cat.Value = "PLCC";
                }
                else if (QFP != null && QFP.Contains(alphaPart))
                {
                    cat.Value = "QFP";
                }
                else if (SOP != null && SOP.Contains(alphaPart))
                {
                    cat.Value = "SOP";
                }
                else {
                    if (cat.Value != "") {
                        cat.Value = "";
                    }

                    cat.FlatStyle = FlatStyle.Flat;
                    cat.Style.BackColor = Color.DarkRed;
                    continue;
                }

                //Setting the matched color
                cat.FlatStyle = FlatStyle.Flat;
                cat.Style.BackColor = Color.SpringGreen;

                //Adding the dropdownlist to the size cb
                (row.Cells[7] as DataGridViewComboBoxCell).DataSource = dgv.AddSeconderyCombobox(dataGridView1, row.Cells[6].Value.ToString());

                if (!matchWithPackage) {
                    continue;
                }

                //Matching the size
 Stop Point     List<string> sizeList = (List<string>)(row.Cells[7] as DataGridViewComboBoxCell).DataSource;
  Doesn't reach this and beyond               List<string> matchedList = sizeList.FindAll(stringToCheck => stringToCheck.Contains(numberPart));

                if (matchedList.Count > 0) {
                    (row.Cells[7] as DataGridViewComboBoxCell).DataSource = matchedList;
                }
            }

1 Ответ

0 голосов
/ 07 января 2020

Итак, я исправляю свою проблему и собираюсь задать свой собственный вопрос, на случай, если кто-нибудь столкнется с подобной проблемой.

if (sizeList != null) {
                    List<string> matchedList = sizeList.FindAll(stringToCheck => stringToCheck.Contains(numberPart));
                    if (matchedList.Count > 0)
                    {
                        (row.Cells[7] as DataGridViewComboBoxCell).DataSource = matchedList;
                    }
                }

После добавления нескольких последних строк в дополнительной проверке, которая необходима для После этого я заметил, что код выполнялся, но matchedlist.count всегда был равен 0.

Итак, получилось так, что код после этого был избыточным, поскольку matchList был равен 0, а отладчик просто пропустил переход к эти строки (немного запутанно, если вы спросите меня).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...