Click here to Skip to main content
13,046,679 members (56,485 online)
Rate this:
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;
            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();

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
Updated 20-Jun-13 3:07am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2017
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