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

[Solved] Select column

5 Answers 248 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.
Huha
Top achievements
Rank 1
Huha asked on 30 Jun 2009, 01:33 PM
Hi,

I have some questions :).

1. How can I select all of the items by clicking to column header?
2. Is there any event for clicking the header?
3. I have a strange error or something. First time I bind a list with 4 columns to the gridview. All of the sorting, ascending is working fine. After this I bind list of a generated class with unknown column number. I use a converter to show the correct data. But sorting and all of the things on the header disappeared.

Regards
János

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 01 Jul 2009, 02:01 PM
Hi Huha,

Unfortunately the current version of RadGridView does not support selection - different from row selection. this means that  you will not be able to select only the cells in a single column.
The good news is that we are working towards the goal of supporting excel -like selection for our future versions. This will enable the user to select columns, rows or individual cells .

On the problem with converters - typically RadGridView would wok with the converters and sorting should be functional. Can you please let me see your code - the converter and the way you bind the RadGridView . I believe we can find a fix for this one.

Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Huha
Top achievements
Rank 1
answered on 02 Jul 2009, 12:22 PM
Hi Pavel,

This is my class:

 

public class GeneratedClass

 

{

 

 

private Dictionary<string, object> Properties = new Dictionary<string, object>();

 

 

public object this[string index]

 {

     

get { return Properties[index]; }

 

     

set { Properties[index] = value; }
}

 

 

}

and here is the converter:

 

public class RowConverter : IValueConverter

 

 

{

 

 

 

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

 

  {

     

GeneratedClass row = value as GeneratedClass;

 

 

     string index = parameter as string
     
return row[index];

 

 

 }

 

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

 

 

 {

     

throw new NotImplementedException();

 

 

 }

}

and here is the way to bulid up the gridview:
var rows = new ObservableCollection<GeneratedClass>();

 

 

 

 

if (e.Result.Count != 0)

 

{

Vir.WebService.

 

ServiceGenerated columnList = e.Result[0];

 

 

 

for (int j = 0; j < columnList.columns.Count; j++)

 

{

 

 

GridViewDataColumn gv = new GridViewDataColumn();

 

gv.IsSortable =

 

true;

 

gv.IsFilterable =

 

true;

 

gv.HeaderText = columnList.columns[j].ToString();

gv.HeaderTextAlignment =

 

TextAlignment.Center;

 

gv.HeaderCellStyle = (

 

Style)this.Resources["HeaderCellStyle"];

 

gv.DataMemberBinding =

 

new System.Windows.Data.Binding();

 

gv.DataMemberBinding.Converter =

 

new RowIndexConverter();

 

gv.DataMemberBinding.ConverterParameter = j.ToString();

 

 

if (j != 0)

 

{

gv.TextAlignment =

 

TextAlignment.Right;

 

gv.DataFormatString =

 

"{0:c}";

 

 

 

//gv.DataFormatString = "{0:N} %";

 

 

 

 

 

 

}

radGV.Columns.Add(gv);

}

 

 

foreach (Vir.WebService.ServiceGenerated item in e.Result)

 

{

 

 

try

 

 

 

 

 

 

{

 

 

GeneratedClass row = new GeneratedClass();

 

 

 

for (int j = 0; j < item.columns.Count; j++)

 

{

 

 

if (j == 0)

 

{

row[j.ToString()] = item.Properties[item.columns[j].ToString()].ToString();

}

 

 

else

 

 

 

 

 

 

{

 

 

if (item.Properties[item.columns[j].ToString()].ToString() != "")

 

{

row[j.ToString()] =

 

Double.Parse(item.Properties[item.columns[j].ToString()].ToString());

 

}

 

 

else

 

 

 

 

 

 

{

row[j.ToString()] = 0;

}

}

}

rows.Add(row);

}

 

 

catch (Exception ex)

 

{

 

 

MessageBox.Show(ex.ToString());

 

}

}

radGV.ItemsSource = rows;

I hope it will be enough :)
Thank you for your reply

János

 

 

0
Pavel Pavlov
Telerik team
answered on 09 Jul 2009, 11:44 AM
Hello Huha,

Please excuse me for the late answer . I had a look at your code. What I understand is that you need a way to bind the RadGridView to a collection with variable count and type of columns.  Your approach with using the value converter to simulate a "datatable -like " behavior is quite interesting. However the underlying value depends on the parameter passed to the converter which happens to be the column index. RadGridView therefore can not extract the underlying value to perform data-wise operations such as sorting / grouping etc.  This is the reason for the missing functionality.

Now the solution  - Since we do not have a real datatable  in Silverlight , we can not gain this without some hacks . Please have a look at  this implementation. There is a project attached with a RadGridView bound to a "light-weight Silverlight DataTable".  I hope you can adapt this approach to your solution.

All the best,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Huha
Top achievements
Rank 1
answered on 10 Jul 2009, 02:20 PM
Hi Pavel,

Thank you very much, It's working now.
But I find an interesting thing. I create a style for column header to able to handle a checkbox which simulate the culomn is selected or not. It looks like this:

 

 

<Style x:Key="MyHeaderCellStyle" TargetType="grid:GridViewHeaderCell">

 

 

 

<Setter Property="Template" >

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="grid:GridViewHeaderCell">

 

 

 

<StackPanel x:Name="pnlSelected" Orientation="Horizontal" Background="Orange">

 

 

 

<CheckBox x:Name="cbxSelected" Background="Orange" IsChecked="True" Unchecked="cbxSelected_Unchecked" Checked="cbxSelected_Checked"/>

 

 

 

<ContentPresenter />

 

 

 

</StackPanel>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

<Setter Property="Foreground" Value="Black" />

 

 

 

<Setter Property="FontWeight" Value="Bold" />

 

 

 

<Setter Property="Background" Value="Transparent" />

 

 

 

</Style>

 


But when I set this style the ordering is working, but the filtering icon disappeared. How can I show this icon with a style?
And how can I check what column's checkbox is checked or not?

Regards,
János
0
Pavel Pavlov
Telerik team
answered on 14 Jul 2009, 12:48 PM
Hi Huha,

The attached sample application demonstrates a way to insert a checkbox in the GridViewHeaderCell via Style.

It also demonstrates a way to make that CheckBox change the color of the owner column. I believe this will fit your scenario of simulating column selection.

Kind regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Huha
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Huha
Top achievements
Rank 1
Share this question
or