如何更改标签以匹配组合框的选定索引?

时间:2015-02-27 20:22:28

标签: c#

这里我有一些工作正常的代码。除了我需要的东西,它现在做得最好。

我有一个我已经命名的标签( lblProfileID ),我需要这个标签来显示与( ProfileID)匹配的( ProfileID )取决于我在组合框中所做的选择,其中存储了所有个人资料名称。

我如何完成这项任务?

       public void QueriesProfile()
    {
        QueryResult queryResultProfile = null;
        String SOQL = "";
        SOQL = "Select Id, Name from Profile";
        queryResultProfile = Sfdcbinding.query(SOQL);

        string profileID = null;
        string ProfileName = null;

        if (queryResultProfile.size > 0)
        {
            for (int i = 0; i < queryResultProfile.size; i++)
            {
                Profile userProfile = (Profile)queryResultProfile.records[i];
                profileID = userProfile.Id;
                ProfileName = userProfile.Name;

                string[] uSersProfile = { ProfileName, profileID };
                listProfile.AddRange(uSersProfile);
                cmbProfile.Items.Add(ProfileName);

                lblProfileID.Text = cmbProfile.SelectedIndex(profileID); /// <--- How do i do this?
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

 public void QueriesProfile()
    {
      cmbProfile.SelectedIndexChanged+=cmbProfile_SelectedIndexChanged;  
      QueryResult queryResultProfile = null;
        String SOQL = "";
        SOQL = "Select Id, Name from Profile";
        queryResultProfile = Sfdcbinding.query(SOQL);

        string profileID = null;
        string ProfileName = null;

        if (queryResultProfile.size > 0)
        {
            for (int i = 0; i < queryResultProfile.size; i++)
            {
                Profile userProfile = (Profile)queryResultProfile.records[i];
                profileID = userProfile.Id;
                ProfileName = userProfile.Name;

                string[] uSersProfile = { ProfileName, profileID };
                listProfile.AddRange(uSersProfile);
                cmbProfile.Items.Add(ProfileName);

              
              
                
            }
        }
    }


 private void cmbProfile_SelectedIndexChanged(object sender, EventArgs e)
        {
          
lblProfileID.Text = cmbProfile.SelectedIndex(profileID);
        }