Exemple #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (this.lstRanges.SelectedItems.Count > 0)
            {
                var item  = this.lstRanges.SelectedItems[0];
                var range = item.Tag as NamedRange;

                if (range != null)
                {
                    using (var dlg = new DefineNamedRangeDialog())
                    {
                        dlg.RangeName = range.Name;
                        dlg.Range     = range;

                        if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                        {
                            range.Name     = dlg.RangeName;
                            range.Comment  = dlg.Comment;
                            range.Position = dlg.Range;

                            item.Text             = dlg.RangeName;
                            item.SubItems[1].Text = dlg.Range.ToAddress();
                            this.grid.CurrentWorksheet.SelectionRange = range;

                            if (range.Worksheet == this.grid.CurrentWorksheet)
                            {
                                this.grid.CurrentWorksheet.SelectionRange = range;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            using (var dlg = new DefineNamedRangeDialog())
            {
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    NamedRange range = DefineNamedRange(this, this.grid.CurrentWorksheet,
                                                        dlg.RangeName, dlg.Comment, dlg.Range);

                    if (range != null)
                    {
                        lstRanges.Items.Add(new ListViewItem(new string[] { range.Name, range.Position.ToAddress() })
                        {
                            Tag = range
                        });

                        if (range.Worksheet == this.grid.CurrentWorksheet)
                        {
                            this.grid.CurrentWorksheet.SelectionRange = range;
                        }
                    }
                }
            }
        }