Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Handling GanttChart on ActivityDialog Using C# ILOG

0.00/5 (No votes)
16 May 2007 1  
This article shows how to handle a GanttChart on an ActivityDialog.

Introduction

I was recently involved in developing a schedule management system using the Gantt Model provided by the C# .NET Framework. I extended ActivityDialog and designed a new dialog that handles customer-specific activity, resource, constraint, and reservation. In this project, I was confronted with a difficulty: how to handle a GanttChart on ActivityDialog. I give you my solution for the problem in this article.

Background

I added a new TabPage (includes a DataGridView) on the ActivityDialog to be able to add/delete/update a new constraint of activity. This DataGridView has two columns (activity and lead time). The activity combobox column means the From-Activity of the constraint. The requirement is to display the selected activity on the GanttChart when you add a new constraint on the ActivityDialog.

Using the code

I needed new combobox to handle the GanttChart, so I defined the DataGridViewExtendedComboBoxColumn class for the activity combo box. In this class, I overrode InitializeEditingControl to add two event handlers: the SelectedIndexChanged handler displays the selected activity on the GanttChart.

public class ProgressActivityDialog : ILOG.Views.Gantt.Windows.Forms.ActivityDialog
{
    public ProgressActivityDialog(InitParamActivityDialog param)
    {
    }
    protected override void OnVisibleChanged(EventArgs e)
    {
        base.OnVisibleChanged(e);
        // When this Dialog opens
        if (this.Visible)
        {
            // Check Return Conditions
            if ((this.tabControl.TabPages == null) || 
                (this.tabControl.TabPages.Count == 0) || 
                (this.currentActivity == null))
            {
                return;
            }
            // Remove Default predecessorsTab on ActivityDialog
            this.tabControl.TabPages.Remove(predecessorsTab);
            // Kojun Activity Only Use resourcesTab on ActivityDialog
            if (currentActivity.BNodeLevel != (int)ActivityNodeLevel.Kojun)
            {
                // Remove Default resourcesTab on ActivityDialog
                this.tabControl.TabPages.Remove(resourcesTab);
            }
            // In case of Event Activity, Set some components of resourcesTab invisible
            if (currentActivity.BEventFlg == 1)
            {
                this.resourcesLabel.Visible = false;
                this.resourcesGrid.Visible = false;
                this.resourceNewGrid.Visible = false;
            }
            // In case of Schedule Organization, Set New Activity's StartTime and EndTime
            if (initParams.dialogType == EnumDialogType.ScheduleOrganization)
            {
                if ((initParams.isNewActivity) && 
                    (currentActivity.BNodeLevel == (int)ActivityNodeLevel.Kojun))
                {
                    if (currentActivity.BEventFlg == 0)
                    {
                        currentActivity.StartTime = DateTime.Now.Date + new TimeSpan(8, 0, 0);
                        currentActivity.EndTime = DateTime.Now.Date + new TimeSpan(17, 0, 0);
                        currentActivity.Duration = new TimeSpan(9, 0, 0);
                    }
                    else
                    {
                        currentActivity.StartTime = DateTime.Now.Date + new TimeSpan(8, 0, 0);
                        currentActivity.EndTime = currentActivity.StartTime;
                        currentActivity.Duration = new TimeSpan(0, 0, 0);
                    }
                    this.startDateTimePicker.Value = currentActivity.StartTime;
                    this.finishDateTimePicker.Value = currentActivity.EndTime;
                }
            }
            // EventHandler When TabPage of TabControl is changed
            tabControl.SelectedIndexChanged += 
                       new EventHandler(TabControl_SelectedIndexChanged);
            // EventHandler When KojunName ComboBox Selected Index is changed
            kojunNameCombo.SelectedIndexChanged += 
                       new EventHandler(KojunNameCombo_SelectedIndexChanged);
            // EventHandler When EventName ComboBox Selected Index is changed
            eventNameCombo.SelectedIndexChanged += 
                       new EventHandler(EventNameCombo_SelectedIndexChanged);
            // EventHandler When IgnoreCalendar Checkbox Checked is changed
            ignoreCalendarChkBox.CheckedChanged += 
                       new EventHandler(IgnoreCalendarChkBox_CheckedChanged);
            // Set notesTab.noteTextBox
            this.noteTextBox.Clear();
            if (currentActivity.BNodeLevel == (int)ActivityNodeLevel.Kojun)
            {
                this.noteTextBox.Text = currentActivity.BCmnt;
            }
        }
    }
    // Set Columns of PredecessorNewGrid DataGridView
    private void SetPredecessorNewGridColumns()
    {
        predecessorsNewGrid.Columns.Clear();
        // Set ExtendedComboBoxColumn for activity field
        DataGridViewExtendedComboBoxColumn activityCombo = 
                      new DataGridViewExtendedComboBoxColumn();
        activityCombo.relatedGanttChart = initParams.ganttChart;            
        activityCombo.DataPropertyName = "Activity";
        activityCombo.DisplayMember = "NODE_NM";
        activityCombo.ValueMember = "NODE_ID";
        SetItemsonConstraintFromActivityNameComboBoxColumn(
                       this.Activity.GanttModel.Activities, activityCombo);
        predecessorsNewGrid.Columns.Add(activityCombo);
        // Set TextBox for leadTime field
        DataGridViewTextBoxColumn leadTimeText = new DataGridViewTextBoxColumn();
        leadTimeText.DataPropertyName = "leadTime";
        predecessorsNewGrid.Columns.Add(leadTimeText);
    }
 
    //
    //
    //
    /// Internal Class: Define predecessorsNewGrid'S DataGridViewComboBoxCell
    internal class DataGridViewExtendedComboBoxCell : DataGridViewComboBoxCell
    {
        public override void InitializeEditingControl(int rowIndex, 
               object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            if (base.DataGridView != null)
            {
                base.InitializeEditingControl(rowIndex, initialFormattedValue, 
                                              dataGridViewCellStyle);
                ComboBox comboBox = base.DataGridView.EditingControl as ComboBox;
                if (comboBox != null)
                {
                    comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                    // Add Event
                    comboBox.SelectedIndexChanged += 
                             new EventHandler(comboBox_SelectedIndexChanged);
                    comboBox.Leave += new EventHandler(comboBox_Leave);
                }
            }
        }
        private void comboBox_Leave(object sender, EventArgs e)
        {
            // Delete Event
            ComboBox comboBox = base.DataGridView.EditingControl as ComboBox;
            if (comboBox != null)
            {
                comboBox.SelectedIndexChanged -= 
                         new EventHandler(comboBox_SelectedIndexChanged);
            }
            comboBox.Leave -= new EventHandler(comboBox_Leave);
        }
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (base.DataGridView != null)
            {
                DataGridViewComboBoxEditingControl cbo = 
                            sender as DataGridViewComboBoxEditingControl;
                if ((cbo.Text.Trim() != string.Empty) && 
                    (cbo.FindStringExact(cbo.Text) != -1))
                {
                    // Move Selected Activity to Left-Up Position on GanttSheet
                    DataGridViewExtendedComboBoxColumn column = 
                       (this.DataGridView.Columns[0]) as DataGridViewExtendedComboBoxColumn;
                    if (column != null)
                    {
                        if (column.relatedGanttChart != null)
                        {
                            GanttChart ganttChart = column.relatedGanttChart;
                            ProgressActivity selectedActivity = 
                              (ProgressActivity)ganttChart.GanttModel.FindActivity(
                               (string)cbo.SelectedValue);
                            // Expand selectedActivity
                            ganttChart.GanttTable.ExpandAll();
                            // Move to Left-Up Position
                            SetFirstVisibleActivityOnGanttChart(ganttChart, selectedActivity);
                        }
                    }
                }
            }
        }
        private void SetFirstVisibleActivityOnGanttChart(GanttChart ganttChart, 
                     ProgressActivity activity)
        {
            // Set GanttChart's FristVisibleTime
            if (activity.StartTime != DateTime.Parse("0001/1/1"))
            {
                ganttChart.FirstVisibleTime = activity.StartTime;
            }
            // Set GanttChart's FirstVisibleRow
            ganttChart.FirstVisibleRow = ganttChart.GanttTable.IndexOfRow(activity);
        }
    }
    /// Internal Class: Define predecessorsNewGrid's DataGridViewComboBoxColumn
    internal class DataGridViewExtendedComboBoxColumn : DataGridViewComboBoxColumn
    {
        public GanttChart relatedGanttChart = null;
        public DataGridViewExtendedComboBoxColumn()
        {
            DataGridViewExtendedComboBoxCell comboBoxCell = 
                                 new DataGridViewExtendedComboBoxCell();
            // Set Cell Template
            this.CellTemplate = comboBoxCell;
        }
    }
}

Points of Interest

This sample shows a way to handle GanttChart by selecting a combo box element on an ActivityDialog.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here