More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Saturday, 6 August 2011 4:24:38 AM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

AS mentioned in How to Create Editable ComboBox in DataGridView, there is no property to enable this for a DataGridView ComboBox. You need to handle the EditingControlShowing event in order to change the DropDownStyle of the ComboBox control to DropDown. Then in the CellValidating event, add the FormattedValue value to the ComboBox list if it doesn't already exist. Note that this method only works when when the DataSource property is not set. Otherwise it will fire the exception"Items collection cannot be modified when the DataSource property is set."

Code:
        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
            {
                DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;
                combo.DropDownStyle = ComboBoxStyle.DropDown;
                combo.TextChanged += new EventHandler(combo_TextChanged);
            }
        }



Code:
        void combo _TextChanged(object sender, EventArgs e)
        {
            this.dataGridView1.NotifyCurrentCellDirty(true);
        }



Code:
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (e.ColumnIndex == myColumn.Index)
            {
                object eFormattedValue = e.FormattedValue;
                if (!myColumn.Items.Contains(eFormattedValue))
                {
                    myColumn.Items.Add(eFormattedValue);
                }
            }
       }



Sponsor
rinomasari  
#2 Posted : Saturday, 21 April 2012 12:25:20 AM(UTC)
rinomasari

Rank: Newbie

Reputation:

Groups: Member
Joined: 21/04/2012(UTC)
Posts: 1

follow the link it will explain how datagridview

http://csharp.net-inform...atagridview-tutorial.htm

masari.
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.