Hello,
I have a radgrid and i have 4 static columns (Name, City, Zip, Country). I want to add more columns, but i need to add these columns dynamically through code (because the number of columns will change). I am having trouble figuring this out. I was hoping there was a "GridViewCheckBoxColumn" like there is a "GridViewComboBoxColumn" but there isn't. I wasn't able to find anything current in the forums and I was just wondering how to achieve this. This is the code I have:
I have a radgrid and i have 4 static columns (Name, City, Zip, Country). I want to add more columns, but i need to add these columns dynamically through code (because the number of columns will change). I am having trouble figuring this out. I was hoping there was a "GridViewCheckBoxColumn" like there is a "GridViewComboBoxColumn" but there isn't. I wasn't able to find anything current in the forums and I was just wondering how to achieve this. This is the code I have:
radGridView1.Columns.Add(new GridViewDataColumn |
{ |
Header = "FullName", |
DataMemberBinding = new System.Windows.Data.Binding("FullName") |
}); |
//todo: all other columns |
int numberOfColumns = 5; //Where 5 is the dynamically changing number |
for (var ct = 0; ct < numberOfColumns; ct++) |
{ |
var cl = new GridViewDataColumn(); |
cl.Header = contacts[0].Lists[ct].ListName; |
cl.DataMemberBinding = new System.Windows.Data.Binding("List" + ct); |
radGridView1.Columns.Add(cl); |
} |
Where I'm adding "GridViewDataColumn"'s I would like to add the Checkbox columns instead.
This is what my XAML looks like:
<UserControl x:Class="RK.CRM.MarketingList.MarketingList.MainPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
mc:Ignorable="d" |
d:DesignHeight="300" d:DesignWidth="400" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"> |
<Grid x:Name="gridMain" Background="White" ShowGridLines="False" Loaded="GridMainLoaded"> |
<Grid.RowDefinitions> |
<RowDefinition/> |
<RowDefinition/> |
</Grid.RowDefinitions> |
<Grid.ColumnDefinitions> |
<ColumnDefinition Width="*"/> |
</Grid.ColumnDefinitions> |
<telerik:RadGridView HorizontalAlignment="Left" Margin="24,117,0,0" |
Name="radGridView1" VerticalAlignment="Top" Width="800" AutoGenerateColumns="false" /> |
</Grid> |
</UserControl> |
Please advise, thanks!!