Customizing VARCHART XGantt ActiveX: Styling, Events, and Data BindingVARCHART XGantt ActiveX is a powerful control for building interactive Gantt charts in Windows desktop applications. It offers a rich API for rendering complex schedules, managing dependencies, and interacting with users. This article walks through practical customization techniques: styling the chart to match your application’s look, handling events to respond to user actions, and binding data to keep the chart synchronized with your backend. Examples focus on common languages and environments where ActiveX controls are used (C++, C#, VB6, and VBA), with conceptual guidance that applies across platforms.
Table of contents
- Overview and key concepts
- Preparing your project and embedding the control
- Styling: colors, fonts, layout, and templates
- Events: user interaction, drag/drop, and custom handlers
- Data binding: approaches, models, and synchronization
- Advanced topics: templates, task grouping, and virtualization
- Best practices and performance tips
- Troubleshooting common issues
- Example projects and code snippets
- Further resources
Overview and key concepts
VARCHART XGantt exposes object models for tasks, rows, columns, timescales, and dependencies. Customization usually touches three main areas:
- Visual presentation (styles, templates, layout)
- Interaction (mouse/keyboard events, drag-drop, selection)
- Data model (task properties, resource assignment, persistence)
Before customizing, identify the elements you need: single tasks, task bars, milestones, rows, headers, and dependency lines. Most customizations are applied by setting properties on these objects or by handling rendering events that let you override default drawing.
Preparing your project and embedding the control
-
Add the VARCHART XGantt ActiveX to your project:
- In Visual Studio (C# / VB.NET): Add Reference → COM → select the VARCHART XGantt control. Then drag the control from the Toolbox onto your Windows Form.
- In C++ (MFC / ATL): Import the type library and create an instance of the control in a dialog or view.
- In VB6 / VBA: Project → Components → select the VARCHART XGantt control, then place it on a form.
-
Initialize the control:
- Set basic properties such as StartDate, EndDate, TimeScale, and DefaultRowHeight.
- Configure columns and headers to match your task data (ID, Name, Start, End, %Complete, Resources).
-
Connect event handlers once the control is loaded and the data model created. Many customizations require responding to events like OnDrawItem, OnMouseDown, or OnTaskChanged.
Styling: colors, fonts, layout, and templates
VARCHART XGantt offers both property-based styling and event-based custom drawing for maximum control.
Property-based styling
Use built-in properties to set global styles quickly:
- Colors: set properties like BackgroundColor, GridColor, BarColor, MilestoneColor.
- Fonts: TitleFont, RowFont, TimescaleFont influence headings and labels.
- Row appearance: DefaultRowHeight, RowSeparatorColor, AlternatingRowColors.
Example (C# pseudocode):
xGanttControl.BackgroundColor = Color.White; xGanttControl.RowFont = new Font("Segoe UI", 9); xGanttControl.BarColor = Color.FromArgb(0, 120, 215); // blue xGanttControl.MilestoneColor = Color.Orange;
Template & style sets
If the control supports style templates, create reusable style objects for different task types (e.g., Development, Testing, Critical). Store these templates and assign them to tasks based on attributes.
Custom drawing (fine-grained control)
For pixel-perfect visuals, handle paint/draw events such as OnDrawTask or OnCustomDraw. These events provide a device context (DC) or graphics object so you can:
- Draw gradient-filled bars
- Render custom progress indicators (striped fills, textures)
- Add icons, hyperlinks, or HTML-like tooltips inside bars
Example pattern (pseudo):
- Subscribe to OnDrawTask
- Inspect task properties (Type, Priority)
- Use GDI/GDI+ or .NET Graphics to draw the bar and overlay text/icons
- Suppress default drawing if fully custom-rendered
Styling dependencies and connectors
Dependency lines can be styled for clarity:
- Line color, thickness, and arrowhead style
- Curved vs. orthogonal routing
- Highlight dependencies on hover/selection
Events: user interaction, drag/drop, and custom handlers
Handling events converts a passive chart into an interactive scheduler.
Common events
- OnTaskClick / OnTaskDoubleClick — open details, edit dialogs, or drill-down views.
- OnTaskChanged — capture edits, validate dates/durations, and propagate changes back to data source.
- OnTaskDragStart / OnTaskDragging / OnTaskDragEnd — implement drag-to-reschedule with validation (e.g., prevent scheduling on weekends or outside working hours).
- OnSelectionChanged — update property panels or enable/disable commands.
Example (VB-like pseudocode):
Private Sub xGantt_OnTaskDoubleClick(taskID As Long) Dim task = GetTaskByID(taskID) ShowEditDialog task End Sub
Implementing drag & drop rules
To enforce business rules during drag:
- Use OnTaskDragStart to record original state.
- During OnTaskDragging, test proposed new start/end against constraints (resource availability, dependencies).
- In OnTaskDragEnd, either commit the change or revert and show a validation message.
Keyboard and accessibility
Support keyboard operations:
- Arrow keys to move selection
- Ctrl+Arrow to nudge dates
- Delete key to remove tasks (with confirmation)
Expose accessible labels and roles to help assistive technologies.
Data binding: approaches, models, and synchronization
There are two common ways to drive XGantt with data: direct object model population and data binding to a data source.
1. Populate object model programmatically
- Create task objects in code, set properties, and add them to the control.
- Useful for simple or in-memory data. Example flow:
- Query database
- For each record, create a Task object: ID, Name, Start, End, %Complete, Resource
- Add to control.Tasks collection
- Call Refresh or Redraw
Advantages: full control over task lifetime and immediate access to API features.
2. Data binding to relational data sources
If VARCHART XGantt supports binding, connect it to a DataSet/DataTable, collection, or custom data provider.
- Map columns to task properties (TaskID, ParentID, Start, End).
- Handle change notifications (INotifyPropertyChanged in .NET) so edits in the UI propagate to the data layer automatically.
- Implement a mediator or adapter if the control’s expected schema differs from your database schema.
Example (C# with a BindingSource):
bindingSource.DataSource = myDataTable; xGantt.DataSource = bindingSource; xGantt.DataMember = "Tasks";
Synchronization and persistence
- OnTaskChanged or collection-changed events, validate and persist changes back to the database.
- Use transactions for multi-record updates (e.g., moving a task and its dependent subtasks).
- Implement optimistic concurrency checks if multiple users may edit schedules concurrently.
Advanced topics: templates, task grouping, and virtualization
Templates and conditional formatting
Define visual templates and apply them based on task attributes:
- Critical tasks show red borders and bold text
- Completed tasks use a greyed-out style with a checkmark icon
Hierarchies and grouping
- Use ParentID or OutlineLevel to display task hierarchies.
- Allow collapse/expand and aggregate progress for parent tasks.
- Provide group-by features (by resource, phase, or priority) with headers that display summary bars.
Virtualization and large datasets
- For very large projects, enable row and column virtualization to keep memory and rendering fast.
- Use lazy loading to fetch detail rows on-demand when the user expands a group or scrolls to a time range.
Best practices and performance tips
- Minimize custom drawing where possible; prefer property-based styling for speed.
- Batch updates: suspend redraw while adding/updating many tasks, then resume and refresh.
- Use virtualization for >5,000 tasks; test memory and rendering on target machines.
- Keep data models normalized; use lightweight DTOs when binding.
- Cache lookups (resource names, icons) to avoid repeated costly operations in draw events.
Troubleshooting common issues
- Flicker or slow redraw: enable double-buffering, reduce custom drawing, and suspend layout during bulk updates.
- Events firing unexpectedly: debouce or guard handlers when programmatic changes trigger events.
- Data mapping errors: ensure field types (dates, integers) match control expectations; handle nulls explicitly.
- Printing issues: render to an off-screen bitmap at print resolution or use the control’s built-in print/export if available.
Example snippets
C# — adding a task and subscribing to change event (pseudo):
var task = xGantt.Tasks.Add(); task.Caption = "Design UI"; task.Start = new DateTime(2025, 9, 1); task.End = new DateTime(2025, 9, 10); task.PercentComplete = 20; xGantt.TaskChanged += XGantt_TaskChanged; xGantt.Refresh();
VB6 — handling double-click (pseudo):
Private Sub xGantt_TaskDblClick(TaskID As Long) MsgBox "Open task editor for ID: " & TaskID End Sub
Custom draw (conceptual):
- In OnDrawTask, use Graphics.DrawRoundedRectangle and FillGradient to render a modern task bar.
- Draw task text centered vertically with ellipsis if it overflows the bar width.
Further resources
- VARCHART XGantt ActiveX API reference (consult the vendor docs for exact property/event names)
- Sample projects from VARCHART (look for WinForms, MFC, and VB6 examples)
- Gantt chart UX patterns and accessibility guidelines
Customizing VARCHART XGantt ActiveX combines styling, event-driven interactivity, and robust data binding. Use property-based styling for performance, custom drawing for unique UI needs, and structured event handlers to keep your data and UI synchronized. With templates, grouping, and virtualization you can scale from small projects to enterprise schedules while maintaining responsiveness and clarity.
Leave a Reply