so next i tried using the RowLoaded event where i want to dynamically put the text on the GridViewDataColumn which am not able to do it.
See below snippet
<
telerik:GridViewDataColumn x:Name="endDateTime" Header="End DateTime" TextWrapping="Wrap">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="txtEndDateTime"/>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
private
void grid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if
(e.Row is GridViewRow)
{
GridViewRow gvr = e.Row;
GAAP_NRCPower_PI_Planned_Event objEvent = e.DataElement as GAAP_NRCPower_PI_Planned_Event;
DateTime endDateTime = objEvent.Start_DateTime.AddHours(objEvent.Duration);
(gvr.FindName("txtEndDateTime") as TextBlock)--> this throws error because it is getting null
}
}
Thanks in Advance.
7 Answers, 1 is accepted
As far as I could understand, you have two properties - StartDateTime and Duration and you want to calculate the EndDataTime based on the previous to and display it in a column. Is that correct ? If yes, you may benefit from the GridViewExpressionColumn.
Maya
the Telerik team
Thank you very much for your reply...
1) Is there any event where i have to write this? or should i write this when am Loading the UserControl??
|
Expression<Func<Products, DateTime>> expression = prod => prod.StartDateTime.AddHours(prod.Duration);
GridViewExpressionColumn column = this.RadGridView1.Columns["TotalValue"] as GridViewExpressionColumn; column.Expression = expression; And 2nd question i have is what can i do if the StartDateTime and Duration are coming from two different List's which can be joined with eventID property in both the List's. Above two are two different questions -- Thanks Raviraj. |
The part of the definition of the GridViewExpressionColumn in the code-behind may be set during the initialization (after the InitiazeComponent()). As far as the second question is concerned, I would need a bit more details about the exact settings of your grid and mainly about the implementation of your business objects. How exactly do you get the values for the StartDataTime and Duration ? How do you connect them with the eventID property ? Generally, any additional information and code-snippets would be helpful.
Best wishes,
Maya
the Telerik team
Grid should display 5 columns (EventName, EventStartDateTime, EventDescription, EventNotes, EventEndDateTime)
where First 4 columns come from EventDetails List which has (EventID, EventName, EventStartDateTime,EventDescription, EventNotes) Properties.
And second list is EventLogList which has (EventId, EventDuration) Properties.
So Now..What i need is to on grid first 4 columns will come from EventDetailsList and the 5th Column EventEndDateTime should be a computed column based on the relation between two LISTS and related with EventID.
I am sending you a sample project illustrating how you may achieve the desired result.
Maya
the Telerik team
Thank you soo much thats perfectly working...
1) When i am using the ExpressionColumn i am not able to see the Filters enabled on the Column. Is there anything specific i need to do enable that Filter.
2) I want to see a ToolTip onFocus each Row of a RadGridView. That Tooltip should display Notes Column from the List binded to the RadGridView.
--
Thanks
Raviraj.
You may take a look at this forum thread considering filtering of a GridViewExpressionColumn. As far as the ToolTip is concerned, you may run through this forum thread.
Maya
the Telerik team