简体   繁体   中英

Dropdown not getting correct value

I am using the following to populate a combobox but I am setting the current entity value to what is in the drop down and the is changed via what row is selected on the treeview.

            dpParentId.DisplayMember = "Value";
            dpParentId.ValueMember = "Key";
            dpParentId.DataSource = cmsContext.GetAllCategoriesFromLookupDropDown();

              public Dictionary<int, string> GetAllCategoriesFromLookupDropDown()
      {
         Dictionary<int,string> list = new Dictionary<int, string>();

           try
        { //for a common table to work i neaded some way to have it that their a blank entry so zero cant be so i have choosen 3 
            foreach (CustomLookup cs in cmsEntities.CustomLookups.Where(a=> a.LookupType==1))
                list.Add(Convert.ToInt32(cs.ID), cs.Description);
        }
        catch (Exception ex)
        {
            throw new EntityContextException("GetAllCategoriesFromLookupDropDown failed.", ex);

        }

        return list;
    }

Then on my treeview selectedchanged event i have the following

     private void rgStandardLookup_SelectionChanged(object sender, System.EventArgs e)
            {

                currentEntity = null;
                try
                {  
                bool oldDataChanged = dataChanged;

            if (rgStandardLookup.SelectedRows.Count > 0)
            {

                currentEntity = rgStandardLookup.SelectedRows[0].DataBoundItem as CustomLookup;
                  txtCode.Text = currentEntity.Code.ToString();
                  txtDescription.Text = currentEntity.Description;
                  chkParent.Checked = Convert.ToBoolean(currentEntity.isParent) ? true : false;
                    LookupType = Convert.ToInt16(currentEntity.LookupType);
                  dpParentId.SelectedValue = Convert.ToInt16(currentEntity.ParentLookUpID);
                }

                }
                 catch (Exception ex)
                {
                    ExceptionBox.Show("An error occurred in the rgStandardLookup_SelectionChanged", ex);
                }

            }

    private void dpParentId_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            try
            {
                if (currentEntity != null)

                { //   currentEntity.ParentLookUpID = Convert.ToInt16(dpParentId.SelectedValue);


                }
            }
            catch (Exception ex)
            {
                ExceptionBox.Show("An error occurred in the dpParentId_SelectedIndexChanged", ex);
            }
        }

Problem is is staying as the first item its not changing based on the value in the database

ID Code Name Description ParentLookUpID LookupType isParent 15 0 NULL 15 1 NULL 2 1 .NET .NET NULL 1 1 3 2 Foxpro Foxpro 2 1 0 4 3 HTML HTML NULL 1 1 5 4 SQL SQL NULL 1 1 6 5 PAMS Pams NULL 1 1 7 6 C# C# NULL 1 1 8 7 VB.NET VB.NET NULL 1 1 14 8 NULL test NULL NULL NULL

so in the drop down it should show 2 for foxpro but its not its staying number 15 ? my main problem is when i try to set the selected value its not being reconized on the drop down its just sitting to record 15 the blank one which is for an empty row

您可能必须使用委托来同步两个保管箱

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM