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

Columns and Binding programmatically

1 Answer 236 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vitaly
Top achievements
Rank 1
Vitaly asked on 30 May 2012, 11:27 PM
Hello,

I use standard WPF DataGrid for building of dynamically columns  in my 'dgFields'. I want to use telerik GridView.
If greatly simplify my code (for standard DataGrid) then I need similar for RadGridView:


dgFields.Columns.Add(new DataGridTextColumn { Binding = new Binding("Name"), Header = "Column name", IsReadOnly = true });
dgFields.Columns.Add(new DataGridTextColumn { Binding = new Binding("Header"), Header = "Header", IsReadOnly = true });
dgFields.Columns.Add(new DataGridCheckBoxColumn { Binding = new Binding("IsVisible"), Header = "Is Visible", IsReadOnly = false });
dgFields.Columns.Add(new DataGridTextColumn { Binding = new Binding("Description"), Header = "Description", IsReadOnly = true, MinWidth = 258 });
 
foreach (var column in myObject.HyperlinkColumns)
{
    var style = new Style(typeof(TextBlock));
    style.Setters.Add(new EventSetter(Hyperlink.ClickEvent, (RoutedEventHandler)EventSetter_OnHyperlinkClickEventHandler));
    dgFields.Columns.Add(new DataGridHyperlinkColumn { Binding = new Binding(column.Name), Header = column.Header, ElementStyle = style });
}


I need Text, Hyperlink and CheckBox columns with binding.

Thanks,
Dmitry

1 Answer, 1 is accepted

Sort by
0
Vitaly
Top achievements
Rank 1
answered on 31 May 2012, 01:15 AM
Solved.

var headerColumn = new GridViewDataColumn
                                {
                                    UniqueName = "header",
                                    Header = "Column header",
                                    DataMemberBinding = new Binding("Header"),
                                    IsReadOnly = true
                                };
 
            var isVisibleColumn = new GridViewCheckBoxColumn
                                    {
                                        UniqueName = "isVisible",
                                        Header = "Is Visible",
                                        DataMemberBinding = new Binding("IsVisible")
                                    };
Tags
GridView
Asked by
Vitaly
Top achievements
Rank 1
Answers by
Vitaly
Top achievements
Rank 1
Share this question
or