Windows Develop Bookmark and Share   
 index > Windows Forms General > Column collection editor in c#
 

Column collection editor in c#

After adding a column into the collection editor using ADD button of collection editor , but if user clicks on cancel buttonbefore it is saved,still column exists in collection editor. how to resolve?
Expected result was column should not be there.
ColumnCollectionEdiotro.cs

public

class ColumnCollectionEditor : CollectionEditor
{

}

--------------------------------

ColumnCollection.cs

public

class ColumnCollection : Collection<T>
{
// Inside this i have overrided the following methods

protected override void InsertItem(int index, T item)

{

base.InsertItem(index, item);

item.Grid =

this.Grid;

OnItemAdded(

new ColumnsEventArgs(item)); ;

}

protected override void RemoveItem(int index)

{

ColumnBase col = this[index];

base.RemoveItem(index);

OnItemsRemoved(

new ColumnsEventArgs(col));

}

protected override void ClearItems()

{

base.ClearItems();

OnItemsCleared(

new ColumnsEventArgs(null));

}


}

bikkisuresh  Thursday, September 24, 2009 9:58 AM

Hi,

 

Sorry. I am not able to reproduce this issue base on your code. I add an item and cancel, then open the edit form, the item doesn’t show. The following is my test.

    public partial class UserControl1 : UserControl

    {

        public UserControl1()

        {

            InitializeComponent();

            base.BorderStyle = BorderStyle.FixedSingle;

        }

 

        private ColumnCollection _TestSimpleItems = new ColumnCollection();

        [Category("Collections")]

 

        public ColumnCollection TestSimpleItems

        {

            get { return _TestSimpleItems; }

        }

    }

/////////////////////////

    public class TestGrid

    {

        public DataGridView Grid = new DataGridView();

    }

 

    public class ColumnCollection : Collection<TestGrid>

    {

        // Inside this i have overrided  the following methods

        public DataGridView Grid = new DataGridView();

        protected override void InsertItem(int index, TestGrid item)

        {           

            base.InsertItem(index, item);

            item.Grid = this.Grid;

            //OnItemAdded(new ColumnsEventArgs(item));

        }

 

        protected override void RemoveItem(int index)

        {

            //ColumnBase col = this[index];

            base.RemoveItem(index);

           //OnItemsRemoved(new ColumnsEventArgs(col));

        }

 

        protected override void ClearItems()

        {

            base.ClearItems();

            //OnItemsCleared(new ColumnsEventArgs(null));

        }

    }

 

Besides, it seems you have created a new CollectionEditor. I am not very sure if there are something causing this issue.


The following is an example about working with CollectionEditor. Hope this helps.


How to Edit and Persist Collections with CollectionEditor

http://www.codeproject.com/KB/cs/dzcollectioneditor.aspx

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Thursday, October 01, 2009 9:36 AM

We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 7:28 AM

You can use google to search for other answers

Custom Search

More Threads

• How to catch the Node selection in a Tree View
• TabControl changing TabPage
• Bitmap array.
• Change name on files???
• Location of Control.ClientRectangle within Control.Bounds?
• Drawing images on top of activeX web browser controls
• Draw a graph in C#
• ABout The Button Events
• Cannot get Internet Explorer to display page, but Firefox works fine.
• WebBrowser. How to redirect when network error or 404? (new user)