Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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
Updated 20-Jun-13 3:07am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900