如何将interger值传递给列表 [英] How to pass interger value to a list
本文介绍了如何将interger值传递给列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计,
我对列表有一些小问题。
Hi Folks,
I have small question regarding lists.
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
{
if (dataSourceNameComboBox.SelectedItem != null)
{
int dataval = Convert.ToInt32(datatypeComboBox.SelectedIndex);
Model.ContProduct.Id= dataval ;
Model.Contlist.ToList<>();
}
}
----- Here I want to pass 'dataval' value to the Model.Contlist.ToList<>(); list to filter the data-----
BLL:
public List<ContlistViewModel> Contlist{ get; set; }
DAL:
public class ContlistViewModel
{
public int Id { get; set; }
public string Name{ get; set; }
public string Description{ get; set; }
}
推荐答案
我不完全确定你的意思是传递'dataval'值到Model.Contlist.ToList<>();列表 - 但我猜这意味着我想用它作为索引
为什么要将整数值转换为整数?
所以试试:
I'm not entirely sure what you mean by "pass 'dataval' value to the Model.Contlist.ToList<>(); list" - but I'm guessing it means "I want to use this as an index"
Why are you converting an integer value to an integer?
So try:
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
{
if (dataSourceNameComboBox.SelectedItem != null)
{
int dataval = Convert.ToInt32(datatypeComboBox.SelectedIndex);
Model.ContProduct.Id= dataval ;
ContListViewModel cvm = Model.Contlist[dataval];
...
}
}
但说实话,我可能会直接使用ContlistViewModel项加载Comboxbox,而是使用SelectedItem属性,覆盖必要时在类中使用ToString。
But to be honest, I'd probably load the Comboxbox with the ContlistViewModel items directly, and use the SelectedItem property instead, overriding ToString in the class as necessary.
这篇关于如何将interger值传递给列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文