Click here to Skip to main content
15,918,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Folks,

I have small question regarding lists.

C#
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; }
        
}
Posted
Comments
Sergey Alexandrovich Kryukov 17-Jun-14 1:10am    
Not clear. What is the integer value you need to pass, what does it represent? Why passing it is a problem?
—SA
apr1234 17-Jun-14 9:17am    
Actually on change event of combobox list I want to display the data. So, I am getting selected index of the combo box and then I am passing it to the list. Then as already list is filled with the data and we are passing filter value as selected index, we will get the data based on the combo box.
If not can you please suggest me some method based on the current data available.
Thanks in advance!!

1 solution

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:
C#
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];
                   ...                    
               }
       }
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.
 
Share this answer
 
Comments
apr1234 17-Jun-14 9:14am    
Thanks for the help.... You are right by using list data I am loading dropdown's change event.
When I pass selected value - dalval into the list, it will filter value in the list and only selected values are displayed on the screen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900