private void ApplyConditionalCellFormatting(DataGridViewCell cell, SearchParams.TargetType targType)
        {
            var modified = false;

            if (CurrentSearch != null)
            {
                var matchText = cell.Value as string;

                if (matchText != null && CurrentSearch.Match(targType, matchText))
                {
                    cell.Style.BackColor = Color.GreenYellow;
                    modified             = true;
                }
            }

            if (ShowNullValuesAsGrayed && string.IsNullOrWhiteSpace(cell.Value as string))
            {
                cell.Style.BackColor = Color.Gainsboro;
                modified             = true;
            }

            if (!modified)
            {
                cell.Style.BackColor = dataGridView1.DefaultCellStyle.BackColor;
            }
        }
Esempio n. 2
0
        public void SelectNextSearchResult()
        {
            if (CurrentSearch == null)
            {
                return;
            }

            var keyColumn = dataGridView1.Columns[Properties.Resources.ColNameKey];

            var currentRow    = dataGridView1.CurrentCell?.RowIndex ?? dataGridView1.RowCount;
            var currentColumn = dataGridView1.CurrentCell?.ColumnIndex ?? -1;

            foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>().ToList().Rotate(currentRow))
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.ColumnIndex <= currentColumn)
                    {
                        continue;
                    }

                    if (!(cell.Value is string s))
                    {
                        continue;
                    }

                    if (CurrentSearch.Match(cell.OwningColumn == keyColumn ? SearchParams.TargetType.Key : SearchParams.TargetType.Text, s))
                    {
                        dataGridView1.CurrentCell = cell;
                        return;
                    }
                }
                // Skip cells only in the currently selected row (the selected row is first in order thanks to Rotate call)
                currentColumn = -1;
            }
        }