Problems with the Combobox

0

I am working in Visual Studio with WinForms. I do the databinding with the combo box in the following way.

cboCurrentSaison.DisplayMember = "Code";
cboCurrentSaison.ValueMember = "ElementID";
cboCurrentSaison.DataSource = eleSaiCur.Elements;

When I perform data entry and save in the database it works fine. In the following function I try to show the information of a product recovered from the database in the following way:

private void ProductTotext(clsScenario Sce)
{
    int var = Sce.CurrentSaison();
    lblInfo.Text = var.ToString();
    txtCode.Text = Convert.ToString(Sce.ScenarioCode);
    txtCreatedD.Text = Convert.ToString(Sce.CreatedDate);
    txtCreatedU.Text = Convert.ToString(Sce.CreatedByUserID);
    txtDesc.Text = Convert.ToString(Sce.ScenarioDesc);
    txtModifiedD.Text = Convert.ToString(Sce.ModifiedDate);
    txtModifiedU.Text = Convert.ToString(Sce.ModifiedByUserID);
    cboStatus.SelectedIndex = Sce.ScenarioStatus;
    cboCurrentSaison.SelectedValue = Sce.CurrentSaison();
    cboPreviousSaison.SelectedValue = Sce.PreviousSaison();
}

The Sce.CurrentSaison () and Sce.PreviousSaison () methods retrieve the value (int type) that corresponds to the valuemember in order to display the displaymember in the combobox. This attempt does not work, any ideas?

    
asked by Juan Carlos Marmolejo Martínez 20.06.2018 в 14:55
source

1 answer

0

The problem was the following: The class that contains ElementID is of type int. But when I made data binding use a string, since the value came from the database. Therefore the Sce.CurrentSaison () and Sce.PreviousSaison () methods should retrieve the value in string instead of int.

Thank you, without your input I would not have been able to find the problem.

    
answered by 21.06.2018 в 16:36