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

Problem binding columns by code

7 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael Hilgers
Top achievements
Rank 1
Michael Hilgers asked on 21 Dec 2012, 09:42 AM
Hello Everyone,

let's start with my code:

The grid
<telerik:RadGridView HorizontalAlignment="Left" Margin="0,139,0,0" Name="radGridViewRights" VerticalAlignment="Top" Width="1069" Height="349" IsFilteringAllowed="False" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserSelect="False" ShowGroupPanel="False" ShowColumnHeaders="True"/>

The code behind:
GridViewDataColumn col1 = new GridViewDataColumn();
col1.UniqueName = "groups";
col1.Header = "";
col1.DataMemberBinding = new System.Windows.Data.Binding("moduleDesc");
col1.Width = 180; 
 
this.radGridViewRights.Columns.Add(col1);
 
foreach (KeyValuePair<int, string> kvp in GDC.groupDescIds)
{
    GridViewCheckBoxColumn col = new GridViewCheckBoxColumn();
    col.UniqueName = kvp.Value;
    col.Header = kvp.Value;
    col.DataMemberBinding = new System.Windows.Data.Binding("group_" + kvp.Key);
    col.Width = 80;
 
    this.radGridViewRights.Columns.Add(col);
}
 
ObservableCollection<ModuleGroupRightsDataSource> data = new ObservableCollection<ModuleGroupRightsDataSource>();
 
ModuleGroupRightsDataSource obj = new ModuleGroupRightsDataSource();
obj.moduleDesc = GDC.moduleDesc_Articles;
obj.group_1 = true;
obj.group_3 = true;
obj.group_8 = true;
 
data.Add(obj);
 
obj = new ModuleGroupRightsDataSource();
obj.moduleDesc = GDC.moduleDesc_Partsgroups;
obj.group_3 = true;
obj.group_8 = true;
 
data.Add(obj);
 
this.radGridViewRights.ItemsSource = data;

The data class
public class ModuleGroupRightsDataSource
{
    public string moduleDesc = "";
    public Boolean group_1 = false;
    public Boolean group_2 = false;
    public Boolean group_3 = false;
    public Boolean group_4 = false;
    public Boolean group_5 = false;
    public Boolean group_6 = false;
    public Boolean group_7 = false;
    public Boolean group_8 = false;
    public Boolean group_9 = false;
    public Boolean group_10 = false;
}


As you may see, i try to bind the data from the 'ModuleGroupRightsDataSource' objects to the columns of the grid. But it's not binding. The rows for the entrys in the itemssource are created (so the grid finds out that there are two rows to show), but the cells are empty and show no values.

I can't find my mistake ... anyone any ideas or hints?

Best Regards and a pleasant Doomsday ;)

Michael

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 21 Dec 2012, 09:45 AM
Hi Michael,

 You need properties for your class - currently you have fields only. :)

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael Hilgers
Top achievements
Rank 1
answered on 21 Dec 2012, 09:52 AM
Hey Vlad,

thanks for your fast reply! But this didn't help ...

Here are my changes:

The data class:
public class ModuleGroupRightsDataSource
{
    private string moduleDesc = "";
    public string ModuleDesc
    {
        get { return moduleDesc; }
        set { moduleDesc = value; }
    }
 
    private Boolean group_1 = false;
    public Boolean Group_1
    {
        get { return group_1; }
        set { group_1 = value; }
    }
 
    private Boolean group_2 = false;
    public Boolean Group_2
    {
        get { return group_2; }
        set { group_2 = value; }
    }
 
    private Boolean group_3 = false;
    public Boolean Group_3
    {
        get { return group_3; }
        set { group_3 = value; }
    }
 
    private Boolean group_4 = false;
    public Boolean Group_4
    {
        get { return group_4; }
        set { group_4 = value; }
    }
 
    private Boolean group_5 = false;
    public Boolean Group_5
    {
        get { return group_5; }
        set { group_5 = value; }
    }
 
    private Boolean group_6 = false;
    public Boolean Group_6
    {
        get { return group_6; }
        set { group_6 = value; }
    }
 
    private Boolean group_7 = false;
    public Boolean Group_7
    {
        get { return group_7; }
        set { group_7 = value; }
    }
 
    private Boolean group_8 = false;
    public Boolean Group_8
    {
        get { return group_8; }
        set { group_8 = value; }
    }
 
    private Boolean group_9 = false;
    public Boolean Group_9
    {
        get { return group_9; }
        set { group_9 = value; }
    }
 
    private Boolean group_10 = false;
    public Boolean Group_10
    {
        get { return group_10; }
        set { group_10 = value; }
    }
}

The code behind
GridViewDataColumn col1 = new GridViewDataColumn();
col1.UniqueName = "groups";
col1.Header = "";
col1.DataMemberBinding = new System.Windows.Data.Binding("ModuleDesc");
col1.Width = 180; 
 
this.radGridViewRights.Columns.Add(col1);
 
foreach (KeyValuePair<int, string> kvp in GDC.groupDescIds)
{
    GridViewCheckBoxColumn col = new GridViewCheckBoxColumn();
    col.UniqueName = kvp.Value;
    col.Header = kvp.Value;
    col.DataMemberBinding = new System.Windows.Data.Binding("Group_" + kvp.Key);
    col.Width = 80;
 
    this.radGridViewRights.Columns.Add(col);
}
 
ObservableCollection<ModuleGroupRightsDataSource> data = new ObservableCollection<ModuleGroupRightsDataSource>();
 
ModuleGroupRightsDataSource obj = new ModuleGroupRightsDataSource();
obj.ModuleDesc = GDC.moduleDesc_Articles;
obj.Group_1 = true;
obj.Group_3 = true;
obj.Group_8 = true;
 
data.Add(obj);
 
obj = new ModuleGroupRightsDataSource();
obj.ModuleDesc = GDC.moduleDesc_Partsgroups;
obj.Group_3 = true;
obj.Group_8 = true;
 
data.Add(obj);
 
this.radGridViewRights.ItemsSource = data;
0
Vlad
Telerik team
answered on 21 Dec 2012, 09:55 AM
Hello,

 Do you have any binding expression errors in the Visual Studio Output window? 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael Hilgers
Top achievements
Rank 1
answered on 21 Dec 2012, 10:12 AM
Oh, yes, there are binding expressing errors .... never looked into the output windows ...

I resolved the issue. What i've changed is the unique name property of the columns. If they MATCH the binding field name, it works, if it NOT MATCHES the binding field name, it's not working. Is this behaviour a bug or is this by design?

Kind Regards,
Michael
0
Vlad
Telerik team
answered on 21 Dec 2012, 10:13 AM
Hello,

 You do not need to set UniqueName if you have DataMemberBinding. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael Hilgers
Top achievements
Rank 1
answered on 21 Dec 2012, 10:19 AM
Okay, thanks for you help and guidance to the right direction ;)

Have a nice Christmas!
0
Vlad
Telerik team
answered on 21 Dec 2012, 10:24 AM
Happy Holidays! :)

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Michael Hilgers
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael Hilgers
Top achievements
Rank 1
Share this question
or