简体   繁体   English

InvalidArgument =值'5'对于'SelectedIndex'无效

[英]InvalidArgument=Value of '5' is not valid for 'SelectedIndex'

I read saved data from tbl in a list, and i want to edit the object, so when i start the program, combobox first to show saved value for that object, and others also to be in the combobox. 我从列表中的tbl中读取了保存的数据,并且我想编辑该对象,因此,当我启动该程序时,组合框首先显示该对象的保存值,其他组合也将出现在组合框中。 Please help ! 请帮忙 !

if (lstP.Count > 0)
{
    for (int i = 0; i < lstP.Count; i++)
    {
        if (Stav.IDP == lstP[i].SP)
        {
            Prim.SelectedIndex = lstP[i].SP;
            //ERROR
            break;
        }
    }
}

SelectedIndex requires a number to be passed. SelectedIndex需要传递一个数字。 What you need is to assign an i to it: 您需要为它分配一个i

if (lstP.Count > 0)
{
    for (int i = 0; i < lstP.Count; i++)
    {
        if (Stav.IDP == lstP[i].SP)
        {
            Prim.SelectedIndex = i;
            break;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InvalidArgument =值&#39;0&#39;对&#39;SelectedIndex&#39;无效 - InvalidArgument=Value of '0' is not valid for 'SelectedIndex' InvalidArgument=“0”的值对“SelectedIndex”无效。 参数名称:SelectedIndex - InvalidArgument=Value of '0' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex System.ArgumentOutOfRangeException:InvalidArgument =值“ 0”对于“ SelectedIndex”无效 - System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'SelectedIndex' c #databound ComboBox:InvalidArgument =值'1'对'SelectedIndex'无效 - c# databound ComboBox : InvalidArgument=Value of '1' is not valid for 'SelectedIndex' invalidargument =值&#39;8&#39;对于&#39;索引&#39;无效 - invalidargument=value of '8' is not valid for 'index' InvalidArgument =值&#39;4&#39;对于&#39;索引&#39;无效 - InvalidArgument=Value of '4' is not valid for 'index' InvalidArgument =值&#39;1&#39;对&#39;索引&#39;无效 - InvalidArgument=Value of '1' is not valid for 'index' InvalidArgument =值&#39;3&#39;对于&#39;rowIndex&#39;无效 - InvalidArgument=Value of '3' is not valid for 'rowIndex' InvalidArgument =值&#39;18&#39;对&#39;SelectedIndex&#39;无效参数名称:SelectedIndex - InvalidArgument=Value '18' is invalid to 'SelectedIndex' Parameter name: SelectedIndex 附加信息:InvalidArgument =值“ 0”对“索引”无效 - Additional information: InvalidArgument=Value of '0' is not valid for 'index'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM