Posts

Showing posts from October, 2010

The wonderful DataGrid

Yes, I'm being sarcastic. So, say you have a DataGrid. You have a set of items, and you want to be a good developer and databind those items to the grid. So far so good. Now, let's say that each item need a combobox because a cell value can have a limited sets of values. Fine, so you set up a data source for your items and a data source for your combobox column: dataGrid.DataSource = viewModel.GridItems; comboBoxColumn.DataSource = viewModel.ComboBoxItems; Then you just make sure that the source column in your data grid has the same value as the Value member of your combobox column and you're pretty much home. Now, the fun begins. Say that the data source in question needs different values in the combobox depending on the row. Not so fun anymore, eh? The solution proved to be to bind the grid as usual, but avoid binding the combobox column. Instead, you subscribe to the DataBindingComplete event of the grid, wherein you apply some magic:    int columnIndex = d

Automatically expand a combobox when you click a combobox cell in a datagridview

Oi, that was a long title! Rhymes well with the DataGridView control, though - there are it's a BIG control and has a LOT of associated types. To the point, though: private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { var editType = dataGridView.CurrentCell.EditType; if (editType == typeof(DataGridViewComboBoxEditingControl)) { dataGridView.BeginEdit(false); if (dataGridView.EditingControl is DataGridViewComboBoxEditingControl) { var editingControl = dataGridView.EditingControl as DataGridViewComboBoxEditingControl; editingControl.DroppedDown = true; } } } Hope this helps, // S

Solved: Visual Studio cannot load its own packages

Problem: Visual Studio cannot load it's own packages, eg. the Forms Designer, TFS plugin or resharper. Solution: Reinstall the .NET Framework (I reinstalled .NET 3.5 with SP1). Hopes this saves you time