Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai

I have a user control with a datagrid called IGrid. I want to add GridViewColumnCollection poperty for it.

From Google i got piece of code which is working
C#
public class DataGridNumericColumn : DataGridTextColumn
        {
            protected override object PrepareCellForEdit(System.Windows.FrameworkElement editingElement, System.Windows.RoutedEventArgs editingEventArgs)
            {
                TextBox edit = editingElement as TextBox;
                edit.PreviewTextInput += OnPreviewTextInput;

                return base.PrepareCellForEdit(editingElement, editingEventArgs);
            }
            void OnPreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
            {
                try
                {
                    Convert.ToInt32(e.Text);
                }
                catch
                {
                   e.Handled = true;
                }
            }
        }

private Collection field = new Collection();
        [Category("Data")]
        [Description("Column Creation")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Collection Columns
        {
            get { return field; }
        }


My question is how to add a new type (DataGridNumericColumn )in the collection

using the above code.

Thanks.

What I have tried:

In a user control I added a datagrid, and the above code, I can get all datagridcollections in <othertypes> of visual tree.
Posted
Updated 2-Mar-16 23:56pm
v3
Comments
Kevin Marois 1-Mar-16 12:55pm    
See this:

http://highoncoding.com/Articles/29_Creating_Datagrid_columns_programmatically.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900