Click here to Skip to main content
14,929,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I had an listview that contains number of rows ,and one textbox box when i write in textbox(eg:10)

then i need to select any ten number of rows in listview, throught programatically in C#.net


i had tried with something like


C#
for (int i = 0; i < int.Parse(textBox1.Text); i++)
              {
                  checkedListView.SelectedItem = checkedListView.Items[i];
              }




but by this thing iam only able to select single row in listview

so please help to achive this requirement
thankq in advanced
Posted

If MultiSelect is set to true, you can use Selected property.
http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewitem.selected.aspx[^]

C#
for (int i = 0; i < int.Parse(textBox1.Text); i++)
{
  checkedListView.Items[i].Selected = true;
}
   
Comments
sivakumarmr10 7-Nov-11 5:49am
   
i had already kept that listview selectionmode= multiple
but no use
sivakumarmr10 7-Nov-11 6:13am
   
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
Take a look at the SelectedIndexCollection[^], it may help.
   
You should just set each items selected property to true. Something like this

C#
int amountToSelect = 0;
           int.TryParse(textBox1.Text,out amountToSelect);
           for (int i = 0; i <= amountToSelect; i++)
           {
               listView1.Items[i].Selected = true;
           }


Hope this helps
   
Comments
sivakumarmr10 7-Nov-11 7:17am
   
iam not getting the "Selected" property it was Showing the RED LINE AS ERROR
what does i mean

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