private void grdAnalysisType_CellClick(object sender, DataGridViewCellEventArgs e) { //Fixes crashing when an empty row is clicked try { //Get typeID from selected row in the datagrid and assign it to typeID String typeID = grdAnalysisType.Rows[grdAnalysisType.CurrentCell.RowIndex].Cells[0].Value.ToString(); //Create new MemberType object to call getTypeCount() with the typeID MemberTypes singleType = new MemberTypes(); int typeCount = singleType.getTypeCount(typeID); //Display typeCount on the UI as a label. txtMemberCount.Text = typeCount.ToString(); //Fill the second Datagrid with the members of the selected Membership Type. grdAnalysisMembers.DataSource = Members.getMembersFromType(typeID).Tables["GOLFMEMBERSLOG"]; //Get the current revenue generated by the member type selected MemberTypes typeIncome = new MemberTypes(); decimal income = typeIncome.getTypeRevenue(typeID); decimal currentRevenue = income * typeCount; txtIncome.Text = currentRevenue.ToString(); } // end try catch (InvalidOperationException) { MessageBox.Show("Please select a non empty row"); } }