Click here to Skip to main content
11,709,393 members (55,784 online)
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 0:34am
Edited 20-Jun-13 3:07am
(no name)89.8K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 580
1 OriginalGriff 250
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,027
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2015
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