private static string GetRestoredFindText( [NotNull] FinderFormState formState, [CanBeNull] ContextSpecificSettings contextSpecificSettings) { if (contextSpecificSettings == null) { return(StringUtils.IsNotEmpty(formState.FindText) ? formState.FindText : null); } return(StringUtils.IsNotEmpty(contextSpecificSettings.FindText) ? contextSpecificSettings.FindText : null); }
private void ApplyState([CanBeNull] FinderFormState state, [CanBeNull] ContextSpecificSettings contextSpecificSettings, bool skipSorting = false) { if (state == null) { _dataGridViewFindToolStrip.FilterRows = true; if (!skipSorting) { ApplyDefaultSortOrder(); } return; } _dataGridViewFindToolStrip.FilterRows = state.FilterRows; _dataGridViewFindToolStrip.MatchCase = state.MatchCase; if (!skipSorting) { // try to restore the saved grid sort state DataGridViewSortState sortState = state.DataGridViewSortState; if (sortState == null || !sortState.TryApplyState(_dataGridView)) { ApplyDefaultSortOrder(); } } if (state.FirstDisplayedScrollingRowIndex > 0) { DataGridViewUtils.TrySetFirstDisplayedScrollingRow( _dataGridView, state.FirstDisplayedScrollingRowIndex); } if (state.FirstDisplayedScrollingColumnIndex > 0) { DataGridViewUtils.TrySetFirstDisplayedScrollinColumn( _dataGridView, state.FirstDisplayedScrollingColumnIndex); } if (KeepFindTextBetweenCalls) { _dataGridViewFindToolStrip.FindText = GetRestoredFindText(state, contextSpecificSettings); } }
private FinderForm([NotNull] IEnumerable <ColumnDescriptor> columnDescriptors, bool allowMultipleSelection = false, bool keepFindTextBetweenCalls = true, [CanBeNull] string filterSettingsContext = null) { Assert.ArgumentNotNull(columnDescriptors, nameof(columnDescriptors)); InitializeComponent(); KeepFindTextBetweenCalls = keepFindTextBetweenCalls; _toolStripStatusLabelMessage.Text = string.Empty; Type type = typeof(T); string typeName = Assert.NotNull(type.FullName, "type has no name: {0}", type); _formStateManager = new FormStateManager <FinderFormState>(this, typeName); _formStateManager.RestoreState(); if (!StringUtils.IsNullOrEmptyOrBlank(filterSettingsContext)) { _contextSettingsPersister = CreateContextSettingsPersister(typeName, filterSettingsContext); _restoredContextSpecificSettings = _contextSettingsPersister.Read(); } _gridHandler = new BoundDataGridHandler <T>( _dataGridView, restoreSelectionAfterUserSort: true); _gridHandler.SelectionChanged += _gridHandler_SelectionChanged; // configure the datagrid _dataGridView.SuspendLayout(); _dataGridView.MultiSelect = allowMultipleSelection; _gridHandler.AddColumns(columnDescriptors); _dataGridView.AutoGenerateColumns = false; _findController = new DataGridViewFindController(_dataGridView, _dataGridViewFindToolStrip); _findController.FindResultChanged += _findController_FindResultChanged; if (allowMultipleSelection) { _toolStripButtonSelectFindResultRows = new ToolStripButton(LocalizableStrings.FinderForm_SelectRows) { Enabled = false, ImageScaling = ToolStripItemImageScaling.None, Image = Resources.SelectAll }; _toolStripButtonSelectFindResultRows.Click += _toolStripButtonSelectFindResultRows_Click; _dataGridViewFindToolStrip.Items.Add( _toolStripButtonSelectFindResultRows); } }