You can assign resources to a specific task first by creating the resource and then assigning the resource to the specific task. Resources can be created at design time, run time, or programmatically. At run time they can be created using the Project Resources dialog box and then assigned to the task using the Task Information dialog box. At design time they can be created using the C1GanttView.Resources Collection Editor and then assigned to the task using the Task.ResourceRefs Collection Editor. Resources can also be created programmatically using the Resource class and Add method.
To add a resource to task1 at design time, complete the following:
To programmatically add a resource to task1, complete the following:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub btnAddResource_Click(sender As Object, e As EventArgs) ' add the new Resource object Dim r As New Resource() r.Name = "Resource 1" r.Cost = 300D ganttView.Resources.Add(r) ' find task1 Dim task1 As Task = ganttView.Tasks.Search("Task 1") If task1 IsNot Nothing AndAlso r IsNot Nothing AndAlso task1.ResourceRefs.Count = 0 Then ' add a resource reference to the task Dim rRef As New ResourceRef() rRef.Resource = r rRef.Amount = 0.5 task1.ResourceRefs.Add(rRef) End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void btnAddResource_Click(object sender, EventArgs e) { // add the new Resource object Resource r = new Resource(); r.Name = "Resource 1"; r.Cost = 300m; ganttView.Resources.Add(r); // find task1 Task task1 = ganttView.Tasks.Search("Task 1"); if (task1 != null && task1.ResourceRefs.Count == 0) { // add a resource reference to the task ResourceRef rRef = new ResourceRef(); rRef.Resource = r; rRef.Amount = 0.5; task1.ResourceRefs.Add(rRef); } } |