Exemplo n.º 1
0
        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridView dgv = sender as DataGridView;

            PropertyInfo pi = typeof(Trace).GetProperty(dgv.Columns[e.ColumnIndex].DataPropertyName);

            if (pi == null)
            {
                return;
            }
            TraceViewAttribute attr = pi.GetCustomAttribute <TraceViewAttribute>();

            if (attr == null)
            {
                return;
            }


            switch (e.Value)
            {
            case Pen p:
                e.CellStyle.BackColor = p.Color;
                e.CellStyle.ForeColor = p.Color;
                break;
            }
        }
Exemplo n.º 2
0
        private void Traces_ListChanged(object sender, ListChangedEventArgs e)
        {
            //TODO: There is a lot of optimalisation possible here!
            dataGridView.Columns.Clear();
            foreach (var pi in typeof(Cursor).GetProperties().Where(p => p.GetCustomAttribute <TraceViewAttribute>() != null))
            {
                TraceViewAttribute attr = pi.GetCustomAttribute <TraceViewAttribute>();
                DataGridViewColumn col;
                dataGridView.Columns.Add(col = new DataGridViewColumn(new DataGridViewTextBoxCell()));

                col.DataPropertyName = pi.Name;
                col.Name             = pi.Name;
                col.HeaderText       = attr.Text == null ? pi.Name : attr.Text;
                col.Width            = attr.Width == 0 ? 100 : attr.Width;
                col.AutoSizeMode     = attr.AutoSizeMode;
            }

            if (dataSource != null)
            {
                foreach (Trace t in dataSource.Traces)
                {
                    DataGridViewColumn col;
                    dataGridView.Columns.Add(col = new DataGridViewColumn(new DataGridViewTextBoxCell()));

                    col.Tag          = t;
                    col.Name         = t.Name;
                    col.HeaderText   = t.Name;
                    col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
            }
            //dataGridView.AutoResizeColumns();
        }
Exemplo n.º 3
0
        public TraceView()
        {
            InitializeComponent();

            this.Controls.Add(dataGridView1);
            dataGridView1.Dock = DockStyle.Fill;
            dataGridView1.RowHeadersVisible     = false;
            dataGridView1.AutoGenerateColumns   = false;
            dataGridView1.RowHeadersVisible     = false;
            dataGridView1.AllowUserToAddRows    = false;
            dataGridView1.AllowUserToDeleteRows = false;


            foreach (var pi in typeof(Trace).GetProperties().Where(p => p.GetCustomAttribute <TraceViewAttribute>() != null))
            {
                TraceViewAttribute attr = pi.GetCustomAttribute <TraceViewAttribute>();
                DataGridViewColumn col;

                if (pi.PropertyType == typeof(bool))
                {
                    col = new DataGridViewCheckBoxColumn();
                }
                else if (pi.PropertyType.IsEnum)
                {
                    if (pi.PropertyType.GetCustomAttributes <FlagsAttribute>().Any())
                    {
                        //https://www.codeproject.com/Articles/24614/How-to-Host-a-Color-Picker-Combobox-in-Windows-For
                        DataGridViewEnumFlagsColumn ccol = new DataGridViewEnumFlagsColumn();
                        ccol.DataSource = Enum.GetValues(pi.PropertyType);
                        col             = ccol;
                    }
                    else
                    {
                        DataGridViewComboBoxColumn ccol = new DataGridViewComboBoxColumn();
                        ccol.DataSource = Enum.GetValues(pi.PropertyType);
                        col             = ccol;
                    }
                }
                else
                {
                    col = new DataGridViewTextBoxColumn();
                }


                dataGridView1.Columns.Add(col);
                col.DataPropertyName = pi.Name;
                col.Name             = pi.Name;
                col.HeaderText       = attr.Text == null ? pi.Name : attr.Text;
                col.Width            = attr.Width == 0 ? 100 : attr.Width;
            }
            dataGridView1.CellFormatting += dataGridView1_CellFormatting;
            dataGridView1.KeyDown        += DataGridView1_KeyDown;
            dataGridView1.CurrentCellDirtyStateChanged += DataGridView1_CurrentCellDirtyStateChanged;
        }
Exemplo n.º 4
0
        public MathView()
        {
            InitializeComponent();

            dataGridView.AutoGenerateColumns = false;
            dataGridView.Dock = DockStyle.Fill;
            Controls.Add(dataGridView);
            dataGridView.AllowUserToAddRows    = false;
            dataGridView.AllowUserToDeleteRows = false;
            dataGridView.AllowUserToResizeRows = false;
            dataGridView.RowHeadersVisible     = false;
            dataGridView.CellFormatting       += DataGridView_CellFormatting;

            try
            {
                foreach (var pi in typeof(MathItem).GetProperties().Where(p => p.GetCustomAttribute <TraceViewAttribute>() != null))
                {
                    TraceViewAttribute attr = pi.GetCustomAttribute <TraceViewAttribute>();
                    DataGridViewColumn col;

                    if (pi.Name == nameof(MathItem.Trace))
                    {
                        traceColumn.DisplayMember = nameof(Trace.Name);
                        traceColumn.ValueMember   = nameof(Trace.Self);
                        col = traceColumn;
                    }
                    else if (pi.Name == nameof(MathItem.Marker1))
                    {
                        markerColumn1.DisplayMember = nameof(Scope.Cursor.ID);
                        markerColumn1.ValueMember   = nameof(Scope.Cursor.Self);
                        col = markerColumn1;
                    }
                    else if (pi.Name == nameof(MathItem.Marker2))
                    {
                        markerColumn2.DisplayMember = nameof(Scope.Cursor.ID);
                        markerColumn2.ValueMember   = nameof(Scope.Cursor.Self);
                        col = markerColumn2;
                    }
                    else if (pi.Name == nameof(MathItem.Function))
                    {
                        functionColumn.DataSource    = MathItem.MathFunctions;
                        functionColumn.DisplayMember = nameof(MathFunction.Name);
                        functionColumn.ValueMember   = nameof(MathFunction.Self);
                        col = functionColumn;
                    }
                    else
                    {
                        col = new DataGridViewTextBoxColumn();
                    }


                    dataGridView.Columns.Add(col);
                    col.DataPropertyName = pi.Name;
                    col.Name             = pi.Name;
                    col.HeaderText       = attr.Text == null ? pi.Name : attr.Text;
                    col.Width            = attr.Width == 0 ? 100 : attr.Width;
                }
            }
            catch (Exception ex)
            {
            }
        }