Type | Description | |||
Item as HITEM | A long expression that indicates the the handle of the item where the bar is inserted. Use the ItemBar(exBarParent) property to access later the handle of the item that hosts the bar. | |||
BarName as Variant | A String expression that indicates the name of the bar being inserted, or a long expression that indicates the index of the bar being inserted. You can find a list of predefined bars here. Use the ItemBar(exBarName) property to access later the bar's name. | |||
DateStart as Variant | A Date expression that indicates the date/time where the bar starts, or a string expression that indicates the start date and time. For instance, the "6/10/2003 10:13", indicates the date and the time. Use the ItemBar(exBarStart) property to access later the start date of the bar. | |||
DateEnd as Variant | A Date expression that indicates the date where the bar ends, or a string expression that indicates the end date and time. For instance, the "6/10/2003 10:13", indicates the date and the time. Use the ItemBar(exBarEnd) property to access later the end point of the bar. | |||
Key as Variant | Optional. A String expression that indicates the key of the bar being inserted. If missing, the Key parameter is empty. If the Item has only a single Bar you can not use the Key parameter, else an unique key should be used. Use the ItemBar(exBarKey) property to access later the key of the bar. | |||
Text as Variant | Optional. A String expression that indicates the text being displayed. The Text may include built-in HTML format. Use the ItemBar(exBarCaption) property to access later the caption of the bar. Use the ItemBar(exBarHAlignCaption/exBarVAlignCaption) to display and align the caption of the bar inside or outside of the bar. |
Use the ShowEmptyBars property to show the bars, even if the start and end dates are identical. If you want to assign multiple bars to the same items, you have to use different keys ( Key parameter ), else the default bar is overwritten. Use the Add method to add new types of bars to the Bars collection. Use the AddLink method to link a bar with another. Use the FirstVisibleDate property to specify the first visible date in the chart area. Use the Key parameter to identify a bar inside an item. If the AddBar method is called multiple time with the same item, the bar is moved. Use the ItemBar property to access a bar inside the item. Use the RemoveBar method to remove a bar from an item. Use the ClearBars method to remove all bars in the item. Use the PaneWidth property to specify the width of the chart. Use the NonworkingDays property to specify the non-working days. Use the NextDate property to compute the next or previous date based on a time unit. Use the ItemBar(exBarToolTip) property to assign a tooltip to a bar. Use the ItemBar(exBarsCount) property to count the number of bars inside in the specified item. Use the ItemBar(exBarData) property to associate an extra data to a bar in the specified item . Use the ItemBar(exBarBackColor) property to change the background or the visual appearance for the portion delimited by the start and end points. Use the AllowCreateBar property to specify whether the user can create new bars using the mouse. Use the GroupBars method to group two or more bars, so when a bar in the group is moved or resized the other bars in the group and related are resized or moved accordingly. The FindBar method looks for the item that hosts a specified bar.
The Color property of the Bar object specifies the color being used to paint the bar. This property changes the colors for all bars with the same name. For instance, if you have 3 "Task" bars, and you are changing the color for the "Task" bar, the color is applied to all "Task" bars in the chart. For instance, in order to provide "Task" bars with different colors, you can use the Copy method to copy the Task bar to a new bar, and use the Color to change the color of the bar. The AllowCellValueToItemBar property allows the cells to display properties of the bars.
The following function generates a Task bar with specified color:
Private Function AddTask(ByVal gantt As EXG2ANTTLibCtl.G2antt, ByVal clr As Long) As String Dim sT As String sT = "Task:" & clr With gantt.Chart.Bars.Copy("Task", sT) .color = clr End With AddTask = sT End Function
The function generates a new bar with the name "Task:color", where the color is the color being used, and retrieves the name of the new bar being added. The Copy method retrieves the bar being found with specified name, or creates a new bar if the name is not found in the Bars collection, so AddTask function gets you the name of the bar you should use to specify the color for the bar being added as in the following sample:
With G2antt1.Items Dim d As Date d = G2antt1.Chart.FirstVisibleDate .AddBar .FirstVisibleItem, AddTask(G2antt1, vbRed), d, d + 4, "Red" End With
The following VB sample adds a "Milestone" bar and a text beside:
With G2antt1.Items h = .AddItem("new task") .AddBar h, "Milestone", "5/30/2005 10:00", "5/31/2005" .AddBar h, "", "5/31/2005", "6/10/2005", "beside", "<fgcolor=FF0000><b>item</b></fgcolor> to change" End With
or
With G2antt1.Items .AddBar .AddItem("new task"), "Milestone", "5/30/2005 10:00", "6/10/2005", , " <fgcolor=FF0000><b>item</b></fgcolor> to change" End With
The following VB sample adds an item with a single "Task" bar:
Dim h As HITEM, d As Date With G2antt1.Items d = G2antt1.Chart.FirstVisibleDate h = .AddItem("new task") .AddBar h, "Task", G2antt1.Chart.NextDate(d, exDay, 2), G2antt1.Chart.NextDate(d, exDay, 4) End With
The following VB sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like ):
Dim h As HITEM, d As Date With G2antt1.Items d = G2antt1.Chart.FirstVisibleDate h = .AddItem("new task ") .AddBar h, "Task", d + 2, d + 4, "K1" .AddBar h, "Split", d + 4, d + 5, "K2" .AddBar h, "Task", d + 5, d + 9, "K3" End With
The bar is composed by three parts: K1, K2 and K3.
The following C++ sample adds a "Milestone" bar and a text beside:
#include "Items.h" COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; CItems items = m_g2antt.GetItems(); long h = items.AddItem( COleVariant( "new task" ) ); items.AddBar( h, COleVariant("Milestone"), COleVariant( "5/30/2005 10:00" ), COleVariant( "5/31/2005" ), vtMissing, vtMissing ); items.AddBar( h, COleVariant(""), COleVariant( "5/31/2005" ), COleVariant( "6/10/2005" ), COleVariant( _T("just a key") ), COleVariant( "<fgcolor=FF0000><b>item</b></fgcolor> to change" ) );
or
#include "Items.h" COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; CItems items = m_g2antt.GetItems(); long h = items.AddItem( COleVariant( "new task" ) ); items.AddBar( h, COleVariant("Milestone"), COleVariant( "5/30/2005 10:00" ), COleVariant( "6/10/2005" ), vtMissing, COleVariant( " <fgcolor=FF0000><b>item</b></fgcolor> to change" ) );
The following C++ sample adds an item with a single "Task" bar:
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; CItems items = m_g2antt.GetItems(); CChart chart = m_g2antt.GetChart(); DATE d = V2D( &chart.GetFirstVisibleDate() ); long h = items.AddItem( COleVariant("new task") ); items.AddBar( h, COleVariant( "Task"), COleVariant( (double)chart.GetNextDate( d, 4096, COleVariant((long)2) ) ), COleVariant( (double)chart.GetNextDate( d, 4096, COleVariant((long)4) ) ), vtMissing , vtMissing );
The following C++ sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; CItems items = m_g2antt.GetItems(); DATE d = V2D( &m_g2antt.GetChart().GetFirstVisibleDate() ); long h = items.AddItem( COleVariant("new task") ); items.AddBar( h, COleVariant( "Task"), COleVariant( d + 2 ), COleVariant( d + 4 ), COleVariant( "K1" ), vtMissing ); items.AddBar( h, COleVariant( "Split"), COleVariant( d + 4 ), COleVariant( d + 5 ), COleVariant( "K2" ), vtMissing ); items.AddBar( h, COleVariant( "Task"), COleVariant( d + 5 ), COleVariant( d + 9 ), COleVariant( "K3" ), vtMissing );
where the V2D function converts a Variant expression to a DATE expression and may look like follows:
static DATE V2D( VARIANT* pvtDate ) { COleVariant vtDate; vtDate.ChangeType( VT_DATE, pvtDate ); return V_DATE( &vtDate ); }
The following VB.NET sample adds a "Milestone" bar and a text beside:
With AxG2antt1.Items Dim h As Integer = .AddItem("new task") .AddBar(h, "Milestone", "5/30/2005 10:00", "5/31/2005") .AddBar(h, "", "5/31/2005", "6/10/2005", "beside", "<fgcolor=FF0000><b>item</b></fgcolor> to change") End With
or
With AxG2antt1.Items Dim h As Integer = .AddItem("new task") .AddBar(h, "Milestone", "5/30/2005 10:00", "6/10/2005", , " <fgcolor=FF0000><b>item</b></fgcolor> to change") End With
The following VB.NET sample adds an item with a single "Task" bar:
With AxG2antt1.Items Dim d As DateTime = AxG2antt1.Chart.FirstVisibleDate Dim h As Integer = .AddItem("new task") .AddBar(h, "Task", AxG2antt1.Chart.NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 2), AxG2antt1.Chart.NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 4)) End With
The following VB.NET sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
With AxG2antt1.Items Dim d As DateTime = AxG2antt1.Chart.FirstVisibleDate Dim h As Integer = .AddItem("new task ") .AddBar(h, "Task", d.AddDays(2), d.AddDays(4), "K1") .AddBar(h, "Split", d.AddDays(4), d.AddDays(5), "K2") .AddBar(h, "Task", d.AddDays(5), d.AddDays(9), "K3") End With
The following C# sample adds a "Milestone" bar and a text beside:
EXG2ANTTLib.Items items = axG2antt1.Items; int h = items.AddItem("new task"); items.AddBar(h, "Milestone", "5/30/2005 10:00", "5/31/2005", null, null); items.AddBar(h, "", "5/31/2005", "6/10/2005", "just a new key", "<fgcolor=FF0000><b>item</b></fgcolor> to change");
or
EXG2ANTTLib.Items items = axG2antt1.Items; int h = items.AddItem("new task"); items.AddBar(h, "Milestone", "5/30/2005 10:00", "6/10/2005", null, " <fgcolor=FF0000><b>item</b></fgcolor> to change");
The following C# sample adds an item with a single "Task" bar:
EXG2ANTTLib.Items items = axG2antt1.Items; int h = items.AddItem("new task"); DateTime d = Convert.ToDateTime(axG2antt1.Chart.FirstVisibleDate); items.AddBar(h, "Task", axG2antt1.Chart.get_NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 2), axG2antt1.Chart.get_NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 4), null, null);
The following C# sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
EXG2ANTTLib.Items items = axG2antt1.Items; int h = items.AddItem("new task"); DateTime d = Convert.ToDateTime( axG2antt1.Chart.FirstVisibleDate ); items.AddBar(h, "Task", d.AddDays(2), d.AddDays(4), "K1", null ); items.AddBar(h, "Split", d.AddDays(4), d.AddDays(5), "K2", null); items.AddBar(h, "Task", d.AddDays(5), d.AddDays(9), "K3", null);
The following VFP sample adds an item with a single "Task" bar:
With thisform.G2antt1.Items d = thisform.G2antt1.Chart.FirstVisibleDate .DefaultItem = .AddItem("new task") .AddBar(0, "Task", thisform.G2antt1.Chart.NextDate(d,4096,2), thisform.G2antt1.Chart.NextDate(d,4096,4)) EndWith
The following VFP sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
With thisform.G2antt1.Items thisform.G2antt1.Chart.FirstVisibleDate = "5/29/2005" .DefaultItem = .AddItem("new task") .AddBar(0, "Task", "5/31/2005", "6/2/2005", "K1", "") .AddBar(0, "Split", "6/2/2005", "6/4/2005", "K2", "") .AddBar(0, "Task", "6/4/2005", "6/9/2005", "K3", "") EndWith