This is a migrated thread and some comments may be shown as answers.

[Solved] Problem with creating button or image in ChildTableDefinitions

1 Answer 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Serg
Top achievements
Rank 1
Serg asked on 13 Aug 2009, 07:35 AM
Hi. I have no problems with viewing buttons or images in my ChildTableDefinitions. I have upadeted controls to newest version and there no buttons in the cells just text. What I have to do?

Here the code for Button.

 public class ButtonDataColumn : GridViewDataColumn
    {
        public string Content { get; set; }
        public RoutedEventHandler ButtonClick { get; set; }
        public int ButtonWidth { get; set; }

        public ButtonDataColumn(string content, RoutedEventHandler buttonClick, int buttonWidth)
        {
            Content = content;
            ButtonClick = buttonClick;
            ButtonWidth = buttonWidth;
        }
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            Button btn = new Button();
            btn.Content = Content;
            btn.Height = 30;        
            btn.Click += ButtonClick;
            btn.Width = ButtonWidth;
            return btn;
        }
}


Here code for Grid


   private void MasterTableDefinition_PreviewDataRowCreate(object sender, DataRecordCreateEventArgs e)
        {
            try
            {                 
                    e.IsExpandableRecord = true;

                    GridViewTableDefinition detailDefinition = new GridViewTableDefinition();
                    detailDefinition.AutoGenerateFieldDescriptors = false;

                    column = new GridViewDataColumn();
                    column.DataMemberBinding = new Binding("Description");
                    column.HeaderText = "Description";
                    column.IsFilterable = false;
                    column.Width = new GridLength(400);
                    detailDefinition.FieldDescriptors.Add(column);


                    column = new GridViewDataColumn();
                    column.DataMemberBinding = new Binding("LanguageName");
                    column.HeaderText = "Language";
                    column.IsFilterable = false;
                    detailDefinition.FieldDescriptors.Add(column);

                    ButtonDataColumn columnbtn = new ButtonDataColumn("Edit", new RoutedEventHandler(EditDescrButton_Click), 50);
                    columnbtn.DataMemberBinding = new Binding("DescriptionID");
                    columnbtn.IsFilterable = false;
                    columnbtn.Width = new GridLength(55);
                    detailDefinition.FieldDescriptors.Add(columnbtn);          
                    
                    detailDefinition.DataSource = ((HolidayRentalsHome.AdminServices.HolidayRentalsReportList)(e.Data)).HolidayDescriptionsListData;
                    e.ChildTableDefinitions.Add(detailDefinition);
                }     
}

Thanks,

 Sergey
      

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 19 Aug 2009, 12:53 PM
Hello Sergey,

You are right - this is definitely a bug and we have fixed this immediately. You need however to change a bit this column in order to make this to work properly. If you want to use inherited columns in child tables you should:

- add parameterless constructor
- override CopyPropertiesFrom() method and copy any custom properties

I've attached small example using our latest build where the problem is fixed.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Serg
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or