/// <summary> /// Add the new column to the collection /// </summary> /// <param name="column">The column to be collected</param> /// <returns>The index position it was added to.</returns> public int Add(SmartColumn column) { int idx = -1; idx = List.Add(column); column.OnTextChange += new EventHandler(OnColumnChange); column.OnWidthChange += new EventHandler(OnColumnChange); if ( OnNew != null ) { SmartColumnCollectionEventArgs args = new SmartColumnCollectionEventArgs(column, SmartChangeType.New); OnNew(this, args); } return idx; }
/// <summary> /// This method will initialise the form members /// </summary> /// <param name="sender">Who sent the event</param> /// <param name="e">What parameter was sent</param> private void OnLoad(object sender, System.EventArgs e) { string memberTitle = Properties.Resources.NGM_001; string roleTitle = Properties.Resources.NGM_002; labInvalid.Text = Properties.Resources.NGM_003; SmartColumn name = new SmartColumn("email",memberTitle, SmartColumnType.ReadOnly, SmartColumnDataType.Text,246); SmartColumn role = new SmartColumn("role",roleTitle, SmartColumnType.DropDown, SmartColumnDataType.Text,125); m_listView.Columns.Add(name); foreach(string defrole in m_roles ) role.AddDefaultValue(defrole); m_listView.Columns.Add(role); }
public void Test_08_SmartListControl() { SmartListControl slc = new SmartListControl(); Assert.IsNotNull(slc, "Smart List Control object is NULL!"); slc.Columns.OnNew += new SmartColumnCollectionEventHandler(scc_OnNew); slc.Rows.OnNew +=new SmartRowCollectionEventHandler(Rows_OnNew); SmartColumn sc = new SmartColumn( "email", "Email Address", SmartColumnType.ReadOnly, SmartColumnDataType.Text, 300); Assert.IsNotNull(sc, "Smart Column object is NULL!"); slc.Columns.Add(sc); SmartRow sr = new SmartRow(); Assert.IsNotNull(sr, "Smart Row object is NULL!"); sr.Columns.OnNew +=new SmartColumnValueCollectionEventHandler(Columns_OnNew); SmartColumnValue sv = new SmartColumnValue("email", "*****@*****.**"); Assert.IsNotNull(sv, "Smart Column Value object is NULL!"); sr.Columns.Add(sv); slc.Rows.Add(sr); Assert.IsTrue(slc.Rows[0].Columns["email"].ColumnValue.ToString() == "*****@*****.**", "Email Address does not match !!"); }
/// <summary> /// A column has been modified. /// </summary> /// <param name="column">The column to be added</param> private void ColumnModified(SmartColumn column) { ColumnHeader ch = m_listView.Columns[column.IndexPosition]; if ( ch != null ) { ch.Text = column.Text; ch.Width = column.Width; ch.TextAlign = HorizontalAlignment.Left; } }
/// <summary> /// Remove the column from the view /// </summary> /// <param name="column">The column to be removed</param> private void ColumnRemoved(SmartColumn column) { if( column.IndexPosition > -1 ) { m_listView.Columns.RemoveAt(column.IndexPosition); // Work out the index positions int newPos = column.IndexPosition; bool isNow = false; // TODO May need to change this logic when the column swap is used. for( int i = 0; i < m_columns.Count; i++ ) { SmartColumn c = m_columns[i]; if ( c.IndexPosition > newPos ) { isNow = true; } if ( isNow ) { c.IndexPosition = newPos; newPos++; } } } }
/// <summary> /// Create the control for the column. /// </summary> /// <param name="column">column to create the control</param> private void CreateColumnControl(SmartColumn column) { switch(column.ColumnType ) { case SmartColumnType.DropDown: ComboBox a = new ComboBox(); a.Name = column.Name; a.DropDownStyle = ComboBoxStyle.DropDownList; foreach( object def in column.GetDefaultValues() ) { a.Items.Add(def); } a.Visible = false; a.Width = column.Width; a.SelectedValueChanged +=new EventHandler(ComboSelectedValueChanged); m_controls.Add(column.Name, a); m_listView.AddEmbeddedControl(a, column.IndexPosition); break; } }
/// <summary> /// A column has been added. /// </summary> /// <param name="column">The column to be added</param> private void ColumnAdded(SmartColumn column) { ColumnHeader ch = new ColumnHeader(); ch.Text = column.Text; ch.Width = column.Width; ch.TextAlign = HorizontalAlignment.Left; int idx = m_listView.Columns.Add(ch); column.IndexPosition = idx; // Do we need to create a combo if ( column.ColumnType != SmartColumnType.ReadOnly ) CreateColumnControl(column); }
/// <summary> /// Get the index position of the column /// </summary> /// <param name="column">The column to search for</param> /// <returns>Index position found or -1 if not found</returns> public int IndexOf(SmartColumn column) { return List.IndexOf(column); }
/// <summary> /// Provide the strongly typed Copy To function /// </summary> /// <param name="array">An array of columns</param> /// <param name="index">The index start position</param> public void CopyTo(SmartColumn[] array, int index) { List.CopyTo(array,index); }
/// <summary> /// Does the specified column exist in the collection /// </summary> /// <param name="value">Column to check for</param> /// <returns>True if it does</returns> public bool Contains( SmartColumn value ) { // If value is not of type SmartListControlColumn, this will return false. return( List.Contains( value ) ); }
/// <summary> /// Remove the specified column /// </summary> /// <param name="value">Column to be removed</param> public void Remove( SmartColumn value ) { List.Remove( value ); if ( OnRemoved != null ) { SmartColumnCollectionEventArgs args = new SmartColumnCollectionEventArgs(value, SmartChangeType.Removed); OnRemoved(this, args); } }
/// <summary> /// Insert the column at the specified position /// </summary> /// <param name="index">Index position</param> /// <param name="value">The column to insearch</param> public void Insert( int index, SmartColumn value ) { List.Insert( index, value ); value.OnTextChange += new EventHandler(OnColumnChange); value.OnWidthChange += new EventHandler(OnColumnChange); if ( OnInserted != null ) { SmartColumnCollectionEventArgs args = new SmartColumnCollectionEventArgs(value, SmartChangeType.New); OnInserted(this, args); } }
/// <summary> /// Creates a new instance of SmartColumnCollectionEventArgs which will contain the entry that fired the event /// </summary> public SmartColumnCollectionEventArgs(SmartColumn entry, SmartChangeType type) { m_type = type; m_entry = entry; }