Hi,
Like I said in my previous post I am testing (playing with) Telerik so I think I will have a couple of posts/threads here during the following weeks.
I put 2 RadGridViews on my form, and tried to add some columns to it. When I used the Property Builder, it was all good (except the fact that every time I clicked on a column (to delete it or something) it brought up the GeneralColumnSetting panel.. that was a little annoying when you want to add 30 columns and then delete 20 of them afterwards).
Now I tried to add some more columns to the grid from code. Here I started to have some problemes as follows:
1- using this
radGridView1.Columns.Add(myColumn);
or
radGridView1.MasterGridViewTemplate.Columns.Add(myColumn);
has the same efect, and I dont see the difference
2-Setting the column name is tricky:
myColumn.HeaderText = "test1";
myColumn.UniqueName = "name1";
myColumn.FieldAlias = "alias1";
myColumn.FieldName = "field1";
I found out that this is the order of what will be displayed. So if the HeaderText is not set, then the UniqueName will be set, if that is not set than the Field Alis will be set, and the FieldName is Column name for further referrence. So if the first 3 is not set than nothing will be displayed.
3-After deleting all the columns which I set from the Property Builder, I tried to set columns jut from the code.
Telerik.WinControls.UI.GridViewTextBoxColumn myColumn = new Telerik.WinControls.UI.GridViewTextBoxColumn();
myColumn.HeaderText = "test1";
radGridView1.MasterGridViewTemplate.Columns.Add(myColumn);
This simple code will not work, for my suprize (it worked before when I was adding columns to the ones I set before in the Property Builder). So I cheked the code generated by the Property Builder.
Here I found: myColumn.IsAutoGenerated = false;
IsAutoGenerated -cannot be found in the list of Intelisence... not nice.
But even setting everything like in the generated code, I still could not add Columns to my grid (the grid showed no columns at runtime).
I found out that you have to use:
((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();
and of course the ending part as well to add Columns.
This is very strange, because you don't need to use this in your code (not in the generated one) when you have at least one column added from the Property Builer or added from code but using the "begin init, etc etc" stuff. So after adding at least one (1) Column to the grid you can use the simple grid.Columns.Add() method...
4 - I put two(2) RadGridViews to my form and created a Column like so:
Telerik.WinControls.UI.GridViewTextBoxColumn myColumn = new Telerik.WinControls.UI.GridViewTextBoxColumn();
myColumn.HeaderText = "test1";
and added this to both of my Grids:
radGridView2.Columns.Add(myColumn);
radGridView1.Columns.Add(myColumn);
First thing that I noticed is that it let me do this. Did not complained that I am adding one column to two controls. When I am asking for the owner grid (tru the template) it is the last Grid I added the column to.
The best part is still this: after running the application, when I try to resize the "test1" column in the second grid, it WILL NOT MOVE during the resize, but in stead the "test1" column in the first grid will show the change...spooky :)
The second grid, where I actually changed the column will not show the change until a forced refresh.
I believe that this is not a normal functionality to a grid and or columns.
I hope I get some answers from Telerik people for my posts. Thank you.
Like I said in my previous post I am testing (playing with) Telerik so I think I will have a couple of posts/threads here during the following weeks.
I put 2 RadGridViews on my form, and tried to add some columns to it. When I used the Property Builder, it was all good (except the fact that every time I clicked on a column (to delete it or something) it brought up the GeneralColumnSetting panel.. that was a little annoying when you want to add 30 columns and then delete 20 of them afterwards).
Now I tried to add some more columns to the grid from code. Here I started to have some problemes as follows:
1- using this
radGridView1.Columns.Add(myColumn);
or
radGridView1.MasterGridViewTemplate.Columns.Add(myColumn);
has the same efect, and I dont see the difference
2-Setting the column name is tricky:
myColumn.HeaderText = "test1";
myColumn.UniqueName = "name1";
myColumn.FieldAlias = "alias1";
myColumn.FieldName = "field1";
I found out that this is the order of what will be displayed. So if the HeaderText is not set, then the UniqueName will be set, if that is not set than the Field Alis will be set, and the FieldName is Column name for further referrence. So if the first 3 is not set than nothing will be displayed.
3-After deleting all the columns which I set from the Property Builder, I tried to set columns jut from the code.
Telerik.WinControls.UI.GridViewTextBoxColumn myColumn = new Telerik.WinControls.UI.GridViewTextBoxColumn();
myColumn.HeaderText = "test1";
radGridView1.MasterGridViewTemplate.Columns.Add(myColumn);
This simple code will not work, for my suprize (it worked before when I was adding columns to the ones I set before in the Property Builder). So I cheked the code generated by the Property Builder.
Here I found: myColumn.IsAutoGenerated = false;
IsAutoGenerated -cannot be found in the list of Intelisence... not nice.
But even setting everything like in the generated code, I still could not add Columns to my grid (the grid showed no columns at runtime).
I found out that you have to use:
((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();
and of course the ending part as well to add Columns.
This is very strange, because you don't need to use this in your code (not in the generated one) when you have at least one column added from the Property Builer or added from code but using the "begin init, etc etc" stuff. So after adding at least one (1) Column to the grid you can use the simple grid.Columns.Add() method...
4 - I put two(2) RadGridViews to my form and created a Column like so:
Telerik.WinControls.UI.GridViewTextBoxColumn myColumn = new Telerik.WinControls.UI.GridViewTextBoxColumn();
myColumn.HeaderText = "test1";
and added this to both of my Grids:
radGridView2.Columns.Add(myColumn);
radGridView1.Columns.Add(myColumn);
First thing that I noticed is that it let me do this. Did not complained that I am adding one column to two controls. When I am asking for the owner grid (tru the template) it is the last Grid I added the column to.
The best part is still this: after running the application, when I try to resize the "test1" column in the second grid, it WILL NOT MOVE during the resize, but in stead the "test1" column in the first grid will show the change...spooky :)
The second grid, where I actually changed the column will not show the change until a forced refresh.
I believe that this is not a normal functionality to a grid and or columns.
I hope I get some answers from Telerik people for my posts. Thank you.