private void StatesGrid_PullSelected(DataRowView g) { this.QueGrid.SelectionChanged -= QueGrid_SelectionChanged; int j = QueGrid.Items.Count; try { using (SqlConnection MomCon = new SqlConnection(MomConStr)) { string h = g.Row.ItemArray[1].ToString(); int JoyStickAssignment = int.Parse(g.Row.ItemArray[3].ToString()); if (JoyStickAssignment != -1) { this.Dispatcher.Invoke(() => SelectedQueTextBox.Text = h); Thread.Sleep(1); this.Dispatcher.Invoke(() => PopulateJoystickSelections(!(bool)QueMode, JoyStickAssignment - 1, SelectedQueTextBox.Text)); } using (SqlCommand cmd = new SqlCommand("momsql..PullAxisTargets", MomCon)) { cmd.Parameters.AddWithValue("@QueName", h); cmd.CommandType = CommandType.StoredProcedure; MomCon.Open(); cmd.ExecuteNonQuery(); MomCon.Close(); } foreach (AxisControl AX in axControl) { this.Dispatcher.Invoke(() => AX.PullSelection()); this.Dispatcher.Invoke(() => AX.queControl = (bool)this.QueMode); this.Dispatcher.Invoke(() => AX.SelectedQue = SelectedQueTextBox.Text); } } } catch { } finally { this.QueGrid.SelectionChanged += QueGrid_SelectionChanged; } }