Okay so I am writting a program that is designed to make scheduling easier at the job I work at right now. Well part of the program is that there is a DB of employees and data that can be edited from the program (pretty straight forward like any program really). Anyway when the user clicks the edit employees button it brings up a new form and a datagridview is populated from an object array of data. Now my question is, I would love to allow the user to sort the array based on what tab they pick (name, ID #, ext) the only problem is when it's an unsort and they click on a row they want to edit I can use the index of that row to access the array of data and change the correct data, the problem is then when sorted the indexes of the datagridview don't match with the index of the array. So what I am asking is did Visual Studio 2010 add a method that allows me to get around this sort with method. As of now I have a chunk of code (from an older program) that scans the array with a for loop for the matching ID#, and once it finds the matching ID# it notes that as the correct index.

Does this make sense? Hopefully it does, anyway and help is appreciated, Thanks!

Why you use index of the row of array (and the same index is then in the dgv)?
Why you simple dont use where clause to the ID?

For example:
your dgv`s row consists of: ID, name, ext (adivce: put id into 1st column)
So when you sort the columns (any of them), the row will still have the same data (id, name nad ext). So you only compare the name with the id.
What I am suggesting here it. that you get the new name, based on the row`s id, not on the row index of dgv.


Is there a reason you have it on an array? If you add the data to a dataset --> datatable, and then set the datatable as the datagridview.datasource, then the datagridview control will handle the sorting and everything else for you.

It would be useful if you specified the type of database you are using; for most types of databases there are adapters that will do the work of updating the database for you so you don have to worry about that part either. If you want to do this manually, i believe the datagridview will tell you the rows that have been changed and you can manipulate the db yourself.


I am using an excel file for my DB (only can I have learned how to use, plus the ppl I am building this for don't have an other software for DBing). The reason I read it to an array is because I feel like if I am constantly accessing the excel file it will be very resource intensive

if it is excel then you can read it as if you were reading a database using ODBC and then place it directly into the dataset.

so you think it would be better to ignore the array and keep calling the excel file, I feel like that will be resource intensive of open and closing the file alot

(oh also I am using Interop for my excel file)