Пример #1
0
        private void btnAddUrl_Click(object sender, EventArgs e)
        {
            string url         = BrowserManager.GetSanitizedUrl(txtUrl.Text);
            string browserName = cboBrowser.Text;
            string matchType   = cboMatchType.Text;

            if (string.IsNullOrWhiteSpace(url) || string.IsNullOrWhiteSpace(browserName))
            {
                return;
            }

            Browser browser = BrowserManager.GetBrowserByName(browserName);

            int rowIndex = -1;

            foreach (DataGridViewRow r in grdRules.Rows)
            {
                if (Convert.ToString(r.Cells[2].Value) == url)
                {
                    rowIndex = r.Index;
                    break;
                }
            }
            DataGridViewRow row;

            if (rowIndex >= 0)
            {
                row = grdRules.Rows[rowIndex];
            }
            else
            {
                row      = grdRules.Rows[grdRules.Rows.Add()];
                rowIndex = row.Index;
            }

            row.Cells[0].Value = grdRules.Rows.Count - 1;
            row.Cells[1].Value = matchType;
            row.Cells[2].Value = url;
            row.Cells[3].Value = imlBrowsers.Images[browserName];
            row.Cells[4].Value = browserName;

            RenumberGridRows();
            SelectRow(rowIndex);
        }