Count number of files c#

Asked

Viewed 74 times

0

Good afternoon! I have a listview with several checkboxes. I want to count all the checkbox files that are selected. I made the following code, but it’s not working.

if (listView.Items[j].CheckState == CheckState.Checked)
                {
                    string countVersions = listView.CheckedItems.Count.ToString();


                        {

                        try
                        {


                            UltraListViewItem item = listView.Items[j];
                            {
                                int countVerao = int.Parse(countVersions);
                                for (int i = 0; i <= countVerao + 1; i++)

                                {
                                    DataBaseUpdate dataBaseUpdate = mUpdater.GetDataBaseUpdateByID((int)item.Tag);

                                    DataBaseUpdateFilesCollection dataBaseUpdateFilesCollection = mUpdater.GetDatabaseUpdateFilesByDataBaseUpdate(dataBaseUpdate.ID);

                                    countFiles = dataBaseUpdateFilesCollection.Count.ToString();

                                    totalFiles = totalFiles + int.Parse(countFiles);
                                }
                                DataBaseUpdateFilesCollection dataBaseUpdateFilesCollection1 = mUpdater.GetDatabaseUpdateFilesByDataBaseUpdate(dataBaseUpdate.ID);
                                mProgressBarPercPerElem = (perc /= (int.Parse(countFiles)));

                                foreach (DataBaseUpdateFiles filesSql in dataBaseUpdateFilesCollection1)
                                {


                                }

My problem is here. It’s always going through the first element of listview, and I want it to go through all the ones that are selected. is (int i = 0; i <= countVerao + 1; i++)

Can someone help me ?

  • I don’t quite understand what you need. What is the return type of the variable dataBaseUpdateFilesCollection.Count and listview.CheckedItems.Count ? because you play for String and then you have to do int.Parse() ?

  • dataBaseUpdateFilesCollection.Count tells me how many files are associated with this Version. In the first version are 77, in the second 60 for example.

  • can put the complete code, where the variable j is declared for example ?

  • I had to do it another way. Thanks anyway.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.