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

[Solved] Control order of columns in display of RadGrid

16 Answers 543 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.
Dheepak Ramaswamy
Top achievements
Rank 1
Dheepak Ramaswamy asked on 17 Feb 2010, 09:17 AM
Hi,

I have a RadGrid which is getting data from a Web Service. The final binding happens in the following manner:

radGridName1.ItemsSource = e.Result;

In the final display, I am getting the columns ordered in alphabetical order of column names even though my service is returning the columns in the order in which I want it to be displayed(which is not alphabetical). How do I set it up so that I get the column order as I get it from the database?

Thanks!
Dheepak

16 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Feb 2010, 09:28 AM
Hello Dheepak,

The grid will not order alphabetically your columns in any way. Can you try standard Silverlight DataGrid temporary to see what will be the result?

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sundar Ramadoss
Top achievements
Rank 1
answered on 15 Apr 2010, 07:21 PM
Hi,

I am also getting the same problem. I have a observable collection and when I bind it to the grid.. it shows the columns in the alphabetical order.

Also help me in how to set the width of the gridview column in runtime.

Please any help in this is appreciated.

Many Thanks,
Sundar
0
Vlad
Telerik team
answered on 16 Apr 2010, 06:43 AM
Hi Sundar,

As I said in my previous reply - the grid will not order columns in any way! You can try your scenario with standard Silverlight DataGrid to see what will be the result. To set width for the columns you can use Width property.

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sundar Ramadoss
Top achievements
Rank 1
answered on 16 Apr 2010, 11:52 PM
Thanks Vlad.

I have found the reason behind this problem. In my code silverlight uses webservice to get the properties class declared in the web part. Webservice order the properties in the alphabetical order. So when it is binded to a grid it shows the columns in an alphabetical order.

I have another problem, please could you help me in this.

I have created a style to display the textbox in a grid column. I need to set the value to it in the runtime.

.Xaml code: -

<

 

telerikGrid:RadGridView x:Name="gridSQLSteps" Height="450" Grid.Row="1" Grid.ColumnSpan="2"    

 

ScrollViewer.VerticalScrollBarVisibility="Visible"   

VerticalAlignment="Top" ShowGroupPanel="False"    

 

 

 

RowEditEnded="gridSQLSteps_RowEditEnded" ColumnWidth="auto" AutoGenerateColumns="False">    

 

<telerikGrid:RadGridView.Columns>   

<telerikGrid:GridViewDataColumn IsReadOnly="True" IsFilterable="False" TextAlignment="Center" Header="StepNo " DataMemberBinding="{Binding StepNo}" x:Name="Number" Width="50" />   
 <telerikGrid:GridViewDataColumn Header="StepSQL" Width="*" IsFilterable="False">  
<telerikGrid:GridViewDataColumn.CellStyle> 
 <Style TargetType="gridView:GridViewCell">
<Setter Property="Template">
<Setter.Value> <ControlTemplate x:Name="ctplStepSQL" TargetType="gridView:GridViewCell">    

<TextBox  x:Name="txtStepSQL" HorizontalAlignment="Left" Width="1030" Text="{Binding StepSQL}" TextWrapping="Wrap"/>  

</ControlTemplate 
</Setter.Value   

 

</Setter   

 

</Style> </telerikGrid:GridViewDataColumn.CellStyle   

 

</telerikGrid:GridViewDataColumn   

 

<telerikGrid:GridViewDataColumn Width="50" IsFilterable="False">    

 

<telerikGrid:GridViewDataColumn.CellStyle>
<Style TargetType="gridView:GridViewCell">    

 

<Setter Property="Template">    

 

<Setter.Value   

 

<ControlTemplate TargetType="gridView:GridViewCell">    

 

<Button x:Name="btnMax_SQL" Content="SQL" Click="btnMax_SQL_Click" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,15,0" />    

 

</ControlTemplate   

 

</Setter.Value   

 

</Setter   

 

</Style   

 

</telerikGrid:GridViewDataColumn.CellStyle   

 

</telerikGrid:GridViewDataColumn   

 

</telerikGrid:RadGridView.Columns>  

</telerikGrid:RadGridView>

I need to set/get the value to the txtStepSQL in runtime. Please let me know if I am not clear.

Thanks,
Sundar

 

 

 

0
Sundar Ramadoss
Top achievements
Rank 1
answered on 19 Apr 2010, 10:37 PM
Hi,

Anyhelp in this is much appreciated. On double click of the textbox (txtStepSQL),  I am opening a new window. I need to capture the user entered value and display it on the textbox (within the radgrid).

I am successful in upto opening the window and getting back the value to the parent window. I am struggling to put that value to the textbox in the radgrid. I am not able to get the reference of it.

Help please!.

Thanks,
Sundar
0
Vlad
Telerik team
answered on 20 Apr 2010, 06:50 AM
Hello,

You can get txtStepSQL value to the event of this control - just cast sender argument to TextBox.

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sundar Ramadoss
Top achievements
Rank 1
answered on 20 Apr 2010, 03:58 PM
Hi Vlad,

Sorry, i think I have not explained my scenario correctly.

I have a textbox control within the radgrid cell. On double click on the cell, I am opening a RadWindow. 

 

//Code called on double click of text box

 

private

 

void txtStepSQL_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

 

{

 

if ((DateTime.Now.Ticks - LastTicks) < 2310000)

 

{

 

TextBox tt = (TextBox)sender;

 

 

this.window.Show();

 

}

LastTicks =

DateTime.Now.Ticks;

 

}

I have a textbox in the opened up Radwindow. I have to show the content in the Radgrid textbox in the Radwindow textbox.

 User can change the content and on close of the window, I have to show the content in the Radwindow textbox to the Radgrid textbox.

//Code called on close of the window

 

void

 

OnWindowClosed(object sender, Telerik.Windows.Controls.WindowClosedEventArgs e)

 

{

 

if (e.DialogResult == true)

 

{

Telerik.Windows.Controls.

RadWindow.Alert(e.PromptResult); // for testing I am just alertintg the user entered value. 

 

}

 

}

0
Vlad
Telerik team
answered on 21 Apr 2010, 07:01 AM
Hi,

I strongly suggest you to avoid searching the visual tree for UI elements and using events for such scenarios -  you can try MVVM instead using two way bindings for both the grid and the window TextBox. If you still want to use old fashioned way you can save reference to the clicked TextBox in a variable (your txtStepSQL_MouseLeftButtonDown) and use it in OnWindowClosed.

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sundar Ramadoss
Top achievements
Rank 1
answered on 21 Apr 2010, 03:34 PM
Thanks Vlad.

This is my first project in Silverlight, so I don't have more knowledge on MVVM using two way binding.

 

 If you can get me a sample project with my scenario will be of much helpful.

Also could you suggest me a good silverlight book which I can use as a reference.

 

Many Thanks, 

Sundar
 

 

 

0
Sundar Ramadoss
Top achievements
Rank 1
answered on 26 Apr 2010, 03:30 PM
Hi Vlad,

Please could you tell me is there any progress in this.

Thanks,
Sundar
0
Vlad
Telerik team
answered on 26 Apr 2010, 03:42 PM
Hi,

You can read more about MVVM here.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sundar Ramadoss
Top achievements
Rank 1
answered on 26 Apr 2010, 09:45 PM
Thanks Vlad.

Was there an example project which suits my requirement?

Thanks,
Sundar
0
Vlad
Telerik team
answered on 27 Apr 2010, 07:14 AM
Hi,

Have you tried some of my suggestions? Do you have any particular problems with some of described approaches?

Greetings,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
preeti
Top achievements
Rank 1
answered on 02 Nov 2010, 10:25 AM
Hi Vlad,

I have a similar problem in saving the order of collumn controls. I am using the sample code from the following link

http://www.telerik.com/community/forums/silverlight/gridview/how-to-save-and-load-settings-with-radgridview-for-silverlight.aspx

here we have a RadGridViewSettings.cs  file. The method looks like this

 

 

public virtual void SaveState()

 

{

 

 

if (grid != null)

 

{

 

 

if (grid.Columns != null)

 

{

Settings.ColumnSettings.Clear();

 

 

foreach (GridViewColumn column in grid.Columns)

 

{

 

 

if (column is GridViewDataColumn)

 

{

 

 

GridViewDataColumn dataColumn = (GridViewDataColumn)column;

 

 

 

ColumnSetting setting = new ColumnSetting();

 

setting.PropertyName = dataColumn.DataMemberBinding.Path.Path;

setting.UniqueName = dataColumn.DataMemberBinding.Path.Path;

setting.Header = dataColumn.Header;

 

 

GridViewHeaderRow headerRow = grid.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault();

 

 

 

if (headerRow != null)

 

{

 

 

IEnumerable<GridViewHeaderCell> cells = headerRow.Cells.OfType<GridViewHeaderCell>();

 

 

 

GridViewHeaderCell cell = (from c in cells

 

 

 

where c.Column.UniqueName == setting.PropertyName

 

 

 

select c).FirstOrDefault();

 

 

 

if (cell != null)

 

{

setting.Width = cell.ActualWidth;

}

}

Settings.ColumnSettings.Add(setting);

}

}

}

 

 

if (grid.FilterDescriptors != null)

 

{

Settings.FilterSettings.Clear();

 

 

foreach (FieldFilterDescription ffd in grid.FilterDescriptors.OfType<FieldFilterDescription>())

 

{

 

 

if (ffd.IsActive)

 

{

 

 

FilterSetting setting = new FilterSetting();

 

setting.Filter1 = ffd.Filter1;

setting.Filter1.MemberType =

 

null;

 

setting.Filter2 = ffd.Filter2;

setting.Filter2.MemberType =

 

null;

 

setting.SelectedValues =

 

new List<Telerik.Windows.Data.FilterDescriptor>(ffd.SelectedValues);

 

 

 

IEnumerable<Telerik.Windows.Data.FilterDescriptor> selectedValues = setting.SelectedValues;

 

 

 

foreach (Telerik.Windows.Data.FilterDescriptor f in selectedValues)

 

{

f.MemberType =

 

null;

 

}

setting.PropertyName = ffd.FieldName;

Settings.FilterSettings.Add(setting);

}

}

}

 

 

if (grid.SortDescriptors != null)

 

{

Settings.SortSettings.Clear();

 

 

foreach (Telerik.Windows.Data.SortDescriptor d in grid.SortDescriptors)

 

{

 

 

SortSetting setting = new SortSetting();

 

setting.PropertyName = d.Member;

setting.SortDirection = d.SortDirection;

Settings.SortSettings.Add(setting);

}

}

 

 

if (grid.GroupDescriptors != null)

 

{

Settings.GroupSettings.Clear();

 

 

foreach (Telerik.Windows.Data.GroupDescriptor d in grid.GroupDescriptors)

 

{

 

 

GroupSetting setting = new GroupSetting();

 

setting.PropertyName = d.Member;

setting.SortDirection = d.SortDirection;

setting.DisplayContent = d.DisplayContent;

Settings.GroupSettings.Add(setting);

}

}

Settings.FrozenColumnCount = grid.FrozenColumnCount;

}

Settings.SaveObj();

}




 if you change the order of grid collumns then in the

SaveState() function in sample code we get the changed collumns while itterating but in my case i am not geting it...Plz help....





so i am tryg to
0
Vlad
Telerik team
answered on 02 Nov 2010, 10:34 AM
Hi preeti,

 You can check the latest version of this approach here

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
preeti
Top achievements
Rank 1
answered on 02 Nov 2010, 11:53 AM
Hi,

i am trying to use ure code for saving my radgridview collums order..
However i am using telerik silverlight grid of older version  2010.1.309.1030.
When i replace your dlls with my version dlls then the collumn ordering does not work.
Is there any alternate way in the previous version to achieve the same.
just change to old dlls check with your code the collumn reordering will not work.


Do let me know asap.
Tags
GridView
Asked by
Dheepak Ramaswamy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sundar Ramadoss
Top achievements
Rank 1
preeti
Top achievements
Rank 1
Share this question
or