12 Answers, 1 is accepted
Thank you for writing.
When the RadGanttView is data bound it does not allow nulls for the start date and end date of a data item. The elements are positioned in the graphical view according to the provided links and dates.
It is possible to use a trick to provide items with null dates. I created an example in which a data table is being used as a data source of the RadGanttView. It contains an item with null values set as start and end dates.
The null dates are substituted with dates out of the bounds of the time line, this way they are not painted in the GraphicalViewElement. Additional information on the different data binding providers you can find here: Working With Data.
If that is not exactly your case please share additional information of what you are trying to accomplish. Besides my project I am also sending you a screen shot of the result on my end.
Regards,
Hristo Merdjanov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Thank for your support.
I'm so sorry that's not exactly my case. I saw in your source code that you change null date value to
if (value == DBNull.Value)
{
row[i] = new DateTime(1904, 10, 15);
}
Because in my project I also need the start and end date for other functions. I need keep date data still be null as it is.
But if the start of end date is null, I will receive an exception when bind data to ganttview.
Is there any advise for my case?
Thanks in advance.
Thank you for writing back.
By design the purpose of the RadGanttView control is to display tasks along a timeline. In this respect it is essential for a data item to have defined Start and End properties.
Since you need to store null dates in your database and you still want to populate these items in the RadGanttView, the best option at the moment would be to use unbound mode: Populating with Data Programmatically. This approach however requires that you keep track of the changes of the populated items in the RadGanttView and update the database accordingly.
Could you please provide us with additional information as to what exactly you are trying to accomplish? How do you imagine an item with a null start and end dates to be painted in the graphical view, what values should be displayed in the corresponding text view? Please send us as detailed information as possible of your task, this is the best way for us to deliver adequate support.
I hope this information is useful. Looking forward to your reply.
Regards,
Hristo Merdjanov
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Hello Hristo,
Thank you for your quick answer.
Here is the details my boss would like to see:
I'd like to display null date data in the ganttview without changing start or end date of it
My data have many record without start or end date, and I'd like to see all of them in the ganttview. The ganttview have two part, text and graphic, in the text, if start or end date is null, I'd see that field is empty like gridview. In graphic, I'd like see nothing in the grapphic for records whose start or end date is null.
Thanks & Regards
Thank you for writing.
As suggested in my previous post one of the options is to use Unbound Mode. In this case you would need to iterate your data coming from the back end and for the objects having null dates populate an item with date set out of the bounds of the RadGanttView. Similar to this you can copy your data to a local field variable, then modify it so that the data is valid and then bind the RadGanttView to it.
Please note that using either approach would require that you keep track of the changes and update the database. I have demonstrated the second approach in the attached project.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Hello Hristo,
Thank you for your reply,
But your solution can not cover my case.
I used you code, and I add n2 new items, one start date is null, one end date is null like my requirements? So you can see some other errors
Thanks
Thank you for writing back.
The internal mechanism for data binding of the RadGanttView does not allow binding to data having null values for the start or the end.
The unbound mode or the approach suggested in my attached project could provide the desired behavior. I made slight modifications to my project to reflect your requirements.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Hello Hristo,
Thank you for your reply,
The problem is the null date items are children of other items whose start and end date are not null. The ganttview autosummary start and end date of childrens item to their parents. Thus, the parents item date are null and that is unexpected result.
You can reproduce by change parent Id of null item in your example to 1, you will see the "Summary task title" start and end date will be null.
Thank & regards,
Thuy
Thank you for writing back.
In this case you could perform a check inside the GraphicalViewItemFormatting event if the ItemElement is GanttViewSummaryItemElement and then assign a Start and End date. Please see my code snippet below:
private
void
radGanttView1_GraphicalViewItemFormatting(
object
sender, Telerik.WinControls.UI.GanttViewGraphicalViewItemFormattingEventArgs e)
{
GanttViewSummaryItemElement summaryItem = e.ItemElement
as
GanttViewSummaryItemElement;
if
(summaryItem !=
null
)
{
e.Item.Start = yourStartDate;
e.Item.End = yourEndDate;
}
}
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik
Hi All
Not sure if this have been answered already, but based on the statement of Thuy below:
[quote]The problem is the null date items are children of other items whose start and end date are not null.[/quote]
Since Unbound is for Display only purposes, does it not make sense to simply put the startdate of the items with Null dates simply as the start date of their respective parents ?
i.e.
if( e.Item.Start==null)
{
e.Item.Start=e.Item.Parent.Start;
}
This will make sense, since the summary includes all children, so the start date can not be before the start date of the Summary/Parent.
For the End, you can easily make it display, by just making the end date = to Start.Adddays(1).
You do not have to save this data since you run in unbound mode, but it will display the relevant items.
Regards
Marius
Thank you for sharing your suggestion.
Indeed, your suggestion is valid and as long as long as it fits a local scenario one can implement it. In this particular case, we could not, however, set a start or end date because they had to remain null or hidden in the timeline view.
I hope this helps.
Regards,
Hristo Merdjanov
Telerik