Example #1
0
        private void testParamsGrid_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            DataGridViewCell keyCell = testParamsGrid[e.ColumnIndex - 1, e.RowIndex];
            DataGridViewCell valCell = testParamsGrid[e.ColumnIndex, e.RowIndex];
            string           key     = keyCell.Value.ToString();
            string           value   = valCell.Value.ToString();

            FormMain.ParamDesc paramDesc = testParamTable[key];
            if (paramDesc.isStrItem())
            {
                selectComboBox = new ComboBox();
                selectComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                selectComboBox.Text          = value;
                selectComboBox.Tag           = valCell;
                selectComboBox.Items.AddRange(paramDesc.getStrList());
                selectComboBox.Parent = testParamsGrid;
                Rectangle rect = testParamsGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
                selectComboBox.Location          = rect.Location;
                selectComboBox.Size              = rect.Size;
                selectComboBox.Text              = value;
                selectComboBox.TextChanged      += Comb_TextChanged;
                selectComboBox.FormattingEnabled = true;
                selectComboBox.Show();
            }
        }
Example #2
0
        private void sensorParamsGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string key   = sensorParamsGrid[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
            string value = sensorParamsGrid[e.ColumnIndex, e.RowIndex].Value.ToString();
            double val;

            FormMain.ParamDesc paramDesc = sensorParamTable[key];
            if (paramDesc.isStrItem())
            {
                if (paramDesc.getStrList().Contains(value) == false)
                {
                    MessageBox.Show(this, "输入值不合法: " + paramDesc.getFormat());
                }
            }
            else
            {
                if (double.TryParse(value, out val) == false)
                {
                    MessageBox.Show(this, "输入值不合法");
                    sensorParamsGrid[e.ColumnIndex, e.RowIndex].Value = paramDesc.getValue();
                    return;
                }

                if (val < paramDesc.getMin() || val > paramDesc.getMax())
                {
                    MessageBox.Show(this, String.Format("输入值超出范围 [{0},{1}]", paramDesc.getMin(), paramDesc.getMax()));
                    sensorParamsGrid[e.ColumnIndex, e.RowIndex].Value = paramDesc.getValue();
                    return;
                }
            }
        }