コード例 #1
0
        private void button_save_Click(object sender, EventArgs e)
        {
            OptionConfig config = BuildConfigFromDataGridView();

            saveFileDialog1.FileName = config.Name;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                OptionConfigWriter writer = new OptionConfigWriter(saveFileDialog1.FileName);
                writer.Write(config);

                Geo.Utils.FormUtil.ShowOkAndOpenDirectory(Path.GetDirectoryName(saveFileDialog1.FileName));
            }
        }
コード例 #2
0
        private OptionConfig BuildConfigFromDataGridView()
        {
            OptionConfig config = new OptionConfig();

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                var name    = row.Cells[0].Value + "";
                var val     = OptionManager.ObjToString(row.Cells[1].Value);
                var comment = row.Cells[2].Value + "";
                var group   = row.Cells[3].Value + "";

                if (String.IsNullOrEmpty(name.Trim()))
                {
                    continue;
                }

                var key    = OptionManager.ParseKey(name);
                var valObj = OptionManager.ParseValue(val, key);

                OptionConfigItem ConfigItem = new OptionConfigItem(key, valObj, group, comment);
                config[ConfigItem.Name] = ConfigItem;
            }
            return(config);
        }
コード例 #3
0
        private void SetAndShow(OptionConfig config)
        {
            //首先清除
            this.dataGridView1.Rows.Clear();

            foreach (var item in config)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.Tag = item;

                DataGridViewTextBoxCell textCell = new DataGridViewTextBoxCell();
                textCell.Value = item.Name;

                DataGridViewCell valueCell = null;
                if (OptionManager.GetTypeByKey(item.Name) == OptionParamType.Bool)
                {
                    valueCell = new DataGridViewCheckBoxCell();
                }
                else
                {
                    valueCell = new DataGridViewTextBoxCell();
                }
                valueCell.Value = item.Value;

                DataGridViewTextBoxCell commentCell = new DataGridViewTextBoxCell();
                commentCell.Value = item.Comment;
                DataGridViewTextBoxCell groupCell = new DataGridViewTextBoxCell();
                groupCell.Value = item.Group;

                row.Cells.Add(textCell);

                row.Cells.Add(valueCell);

                row.Cells.Add(commentCell);
                row.Cells.Add(groupCell);

                this.dataGridView1.Rows.Add(row);

                //下拉菜单否
                //(0:llh,1:xyz,2:single,3:posfile,4:rinexhead,5:rtcm)

                if (item.IsEnumType())
                {
                    var names = Enum.GetNames(OptionManager.GetSysType(item.Name));

                    var sourceItems = new List <string>(names);

                    ComboBox comboBox = new ComboBox();
                    comboBox.DropDownStyle         = ComboBoxStyle.DropDownList;
                    comboBox.Name                  = item.Name.ToString();
                    comboBox.DataSource            = sourceItems;
                    comboBox.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
                    comboBox.DrawItem             += comboBox1_DrawItem;

                    //将下拉列表加入到DataGridView的控件集合内,否则下拉列表不会显示在你点击的单元格上
                    comboBox.Visible = false;
                    this.dataGridView1.Controls.Add(comboBox);
                }
                //if(OptionManager.GetTypeByKey(item.Name) == OptionParamType.Bool)
                //{
                //    CheckBox checkBox = new CheckBox();
                //    checkBox.Name = item.Name.ToString();
                //    checkBox.Tag = item;
                //    checkBox.Visible = false;
                //    checkBox.CheckedChanged += CheckBox_CheckedChanged;

                //    this.dataGridView1.Controls.Add(checkBox);
                //}
            }
        }