//Get selected persons and bind them with current selected file private void AddingPersonsToFile(DataGridView dgp) { FilePersonKeywordClient client = new FilePersonKeywordClient(); Int32 selectedRowCount = dgp.Rows.GetRowCount(DataGridViewElementStates.Selected); //getting number of selected rows for (int i = 0; i < selectedRowCount; i++) { Console.WriteLine(dgp[0, dgp.SelectedRows[i].Index].Value.ToString()); client.InsertPersonIntoFile(Convert.ToInt32(dgp[0, dgp.SelectedRows[i].Index].Value), listBox_Files.SelectedItem.ToString()); } client.Close(); }