private void dataGridViewFilter_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == 0) { DataGridViewCell operationCell = dataGridViewFilter.Rows[e.RowIndex].Cells[1]; object oldSelectedItem = operationCell.Value; operationCell.Value = string.Empty; DataGridViewCell fieldCell = dataGridViewFilter.Rows[e.RowIndex].Cells[0]; string filterName = fieldCell.Value.ToString(); IILStubEventFilterDef filterDef = ILStubEventFilterManager.GetInstance().GetFilterDef(filterName); if (filterDef != null) { List <string> operations = filterDef.Operations; DataGridViewComboBoxCell comboBoxOperationCell = operationCell as DataGridViewComboBoxCell; comboBoxOperationCell.Items.Clear(); comboBoxOperationCell.Items.AddRange(operations.ToArray()); if (oldSelectedItem != null && comboBoxOperationCell.Items.Contains(oldSelectedItem)) { comboBoxOperationCell.Value = oldSelectedItem; } } } }
private void toolStripButtonRefresh_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; ILStubEventFilterList listFilter = new ILStubEventFilterList(); int rowCount = dataGridViewFilter.Rows.Count; for (int i = 0; i < rowCount; i++) { DataGridViewRow dataGridViewRow = dataGridViewFilter.Rows[i]; if (dataGridViewRow.IsNewRow) { continue; } if (dataGridViewRow.Cells[0].Value == null) { MessageBox.Show("The field of row " + (i + 1) + " is empty."); return; } string filterName = dataGridViewRow.Cells[0].Value.ToString(); IILStubEventFilterDef filterDef = ILStubEventFilterManager.GetInstance().GetFilterDef(filterName); Debug.Assert(filterDef != null); if (dataGridViewRow.Cells[1].Value == null) { MessageBox.Show("The operation of row '" + filterName + "' is empty."); return; } string operaton = dataGridViewRow.Cells[1].Value.ToString(); if (dataGridViewRow.Cells[2].Value == null) { MessageBox.Show("The value of row '" + filterName + "' is empty."); return; } string value = dataGridViewRow.Cells[2].Value.ToString(); try { IILStubEventFilter filter = filterDef.CreateFilter(operaton, value); listFilter.Add(filter); } catch (FilterOperationIsNullException ex) { MessageBox.Show(String.Format( Resource.ResourceManager.GetString("Wrn_FilterOperationIsNull"), ex.FilterName)); return; } catch (FilterOperationNotSupportException ex) { MessageBox.Show(String.Format( Resource.ResourceManager.GetString("Wrn_FilterOperationNotSupport"), ex.Operation, ex.FilterName)); return; } catch (FilterValueIsNullException ex) { MessageBox.Show(String.Format( Resource.ResourceManager.GetString("Wrn_FilterValueIsNull"), ex.FilterName)); return; } catch (FilterValueNotIntegerException ex) { MessageBox.Show(String.Format( Resource.ResourceManager.GetString("Wrn_FilterValueNotInteger"), ex.Value, ex.FilterName)); return; } } m_filterList = listFilter; UpdateFilterMessage(); UpdateEventList(); } finally { this.Cursor = Cursors.Default; } }