0

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

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;
        }
    }
}

From Google i got a piece of code `

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

Here I can get GridViewColumnCollection in visual tree , My question is how to add a new type (DataGridNumericColumn )in the collection using the above code.

enter image description here

1
  • please any one respond Commented Mar 5, 2016 at 3:40

1 Answer 1

0

If you do not know what the code does, it is probably best to research it before attempting to use it or come up with your own solution. As far as I can tell, you are attempting to add an additional property to a UserControl that inherits DataGrid.

You have two options:

  1. Create a DependencyProperty (the best choice, in my opinion).
  2. Create a normal property

Here's a couple links to help you get started:

What is the difference between Property and Dependency Property

When should I use dependency properties in WPF?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.