private void RefreshDevicesTimer_Tick(object sender, System.EventArgs e) { ControllerDevice selectedItem = null; int selectedCell = 0; if (DevicesDataGridView.SelectedCells.Count > 0) { selectedItem = (ControllerDevice)DevicesDataGridView.SelectedCells[0].OwningRow.DataBoundItem; selectedCell = DevicesDataGridView.SelectedCells[0].ColumnIndex; } ScanJoysticks(); foreach (DataGridViewRow row in DevicesDataGridView.Rows) { ControllerDevice rowObject = (ControllerDevice)row.DataBoundItem; if (selectedItem != null && rowObject == selectedItem) { DevicesDataGridView.ClearSelection(); row.Cells[selectedCell].Selected = true; break; } } }
private void DevicesDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && e.RowIndex >= 0) { DevicesDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); bool enabled = (bool)this.DevicesDataGridView.CurrentCell.Value == true; this.DevicesDataGridView.Rows[e.RowIndex].Cells[0].Value = enabled; ControllerDevice selectedDevice = (ControllerDevice)this.DevicesDataGridView.Rows[e.RowIndex].DataBoundItem; if (enabled) { selectedDevice.OnStateUpdated += Device_OnStateUpdated; } else { selectedDevice.OnStateUpdated -= Device_OnStateUpdated; } } }
private void RefreshButton_Click(object sender, EventArgs e) { DevicesDataGridView.Invalidate(); }