Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Need urgent help here
I have a data grid showing company name and filters in drop down
/* filters in drop down are according to company name in that row *\
 
//for binding list to combo box on its click
private void dgvJournalEntries_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            //selection of combo box
            List<UDT.MgmtJournalEntryEnterprise> LstCompanyFiltersGrdOpr =       this.bsEnterpriseCompanyFIlter.DataSource as List<UDT.MgmtJournalEntryEnterprise>;
            if (dgvJournalEntries.Columns[dgvJournalEntries.CurrentCell.ColumnIndex].Name == "CompanyFilters")
            {
                ComboBox combo = e.Control as ComboBox;
                if (combo != null)
                {
                    // Remove an existing event-handler, if present, to avoid  
                    // adding multiple handlers when the editing control is reused.
                    combo.DropDown -= new EventHandler(combo_DropDown);
                    // Add the event handler. 
                    combo.DropDown += new EventHandler(combo_DropDown);
                }
            }
        }
//And for Binding List
  void combo_DropDown(object sender, EventArgs e)
        {
            List<UDT.MgmtJournalEntryEnterprise> LstCompanyFiltersGrdOpr = this.bsEnterpriseCompanyFIlter.DataSource as List<UDT.MgmtJournalEntryEnterprise>;
            ComboBox combo = sender as ComboBox;
            combo.BeginUpdate();
            int currentColIndex = dgvJournalEntries.CurrentCell.ColumnIndex;
            int currentRowIndex = dgvJournalEntries.CurrentCell.RowIndex;
            string preColumnCompanyValue = dgvJournalEntries[currentColIndex - 1, currentRowIndex].Value.ToString();
            var CompanyFilterList = LstCompanyFiltersGrdOpr.Where(X => X.CompanyName == preColumnCompanyValue).SelectMany(X => X.tEDJFilterList).ToList();
            if (CompanyFilterList.Count() > 0)
            {
                combo.DataSource = CompanyFilterList.Select(C => C.FName).ToList();
            }
            combo.EndUpdate();
        }
But the issue is after selecting a value in from drop down when i click on any other cell or row , previous drop down lost its selected value
Posted 20-Jun-13 1:34am
Edited 20-Jun-13 4:07am
(no name)83.7K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 Sergey Alexandrovich Kryukov 170
4 PIEBALDconsult 160
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100