Click here to Skip to main content
15,881,725 members
Articles / Desktop Programming / Windows Forms

Handling GanttChart on ActivityDialog Using C# ILOG

Rate me:
Please Sign up or sign in to vote.
2.05/5 (6 votes)
16 May 2007CPOL 37.6K   697   13   2
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.

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Japan Japan
Ph.D(Computer Network)
Project Manger
Developer

Comments and Discussions

 
QuestionWhat are you talking about? Pin
Charles J Cooper30-Jul-07 10:04
Charles J Cooper30-Jul-07 10:04 
AnswerRe: What are you talking about? Pin
Danielku1521-Sep-08 4:21
Danielku1521-Sep-08 4:21 
I think he is talking about the ILog Gantt for .net
http://www.ilog.com/products/ganttnet/[^]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.