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

Is there a grid template column for RadGridView?

2 Answers 150 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gunther
Top achievements
Rank 1
gunther asked on 04 Feb 2011, 05:08 PM
I am working on my first WPF app and am trying to find similar functionality in the RadGridView that exists in the RadGrid for ASP.NET which I have lots of experience in.

With RadGrids, I could create a GridTemplateColumn that contains various controls like labels and dropdowns that I could acquire instances of using .FindControl() in the codebehind's ItemDataBound event.  I could then put any text I wanted into these controls based on logic in the codebehind.

I discovered the DataTemplate object in the RadGridView, but it seems I can only use this to bind data from an object's member property.  What I want to do is insert my own custom information directly rather than rely on an object member since the data I want to display might not be offered by any member within the object.

Links to where this information can be found will be all I need unless you'd like to offer any other additional info here.

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 04 Feb 2011, 05:28 PM
Hi gunther,

usually, you can use a Converter (IValueConverter) in this case.
Its Convert method is called for each item (similarly as ItemDataBound event) and you can return anything  you want.

Kind regards,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
gunther
Top achievements
Rank 1
answered on 07 Feb 2011, 09:59 PM

I don't think that's what I need.  Let me explain this better with an example.  Here's an ItemDataBound event of an ASP.NET RadGrid:

void rgTest_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
  GridDataItem Item = e.Item as GridDataItem;
  int i = e.Item.ItemIndex + 1;

  Literal ltMessage = Item["Message"].FindControl("ltMessage") as Literal;

  if (i % 4 == 0)
   ltMessage.Text = "This row is evenly divisible by 4";
  else if (i % 3 == 0)
   ltMessage.Text = "This row is evenly divisible by 3";
  else if (i % 2 == 0)
   ltMessage.Text = "This row is evenly divisible by 2";
 }
}

Notice how I am acquiring an instance of a literal control in the grid and using conditional logic to determine what is displayed in the control without directly relying on any object member of the datasource.  This is what I would like to do in WPF with your RadGridView control. 

If my question is related more to core functionaly of WPF in and of itself, I will just try to brush up more on WPF since it is brand new to me.

Tags
GridView
Asked by
gunther
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
gunther
Top achievements
Rank 1
Share this question
or