Skip to main content

Blog

C# - DataGridView - Disable Column Sorting

Sometime you need to disable the ability for users to sort on a column and you can easily do this by setting the DataGridViewColumn.SortMode property to desired value.

Here are the steps for achieving this behavior:

1) Righ click on the DataGridView

2) Choose the Edit Columns option

3) Select the column that you want to disable sorting logic for

4) Set the SortMode property to NotSortable

C# - DataGridView - Enable Typing In Combobox Cell

Default behavior of a DataGridViewComboBoxCell is that it doesn't support typing into the cell.

But you could have a request from the client who wants to have enabled typing in a Combobox cell. In order to achieve this, you need to perform two things:

- the DropDownStype property of the ComboBox editing control needs to be set to DropDown. This will enable typing in the combobox.

SilverStripe - How to Logout Inactive Users

SilverStripe content management system is near version 3, the latest stable version that will be released in several months, and we continue to provide SilverStripe tips and tricks to you.

This article shows how to logout inactive user after some period of time.

C# - DataGridView - How to Make Image Column Not Show Any Images

If a DataGridView control on your form contains an image column and cell and need to display null values, it will be replaced with the standard "X" image.

If you need different behavior, i.e. to make sure that no image will be displayed, you have to change the NullValue property of the column to "null".

Here is the code example demonstrates setting the NullValue for an image column:

this.dataGridViewImageColumn1.DefaultCellStyle.NullValue = null;

C# - DataGridView - Cell Text Wrap

By default, text in a DataGridViewTextBoxCell does not wrap. This can be controlled via the WrapMode property on the cell style (e.g. DataGridView.DefaultCellStyle.WrapMode).

Set the WrapMode property of a DataGridViewCellStyle to one of the DataGridViewTriState enumeration values. 

The following code example uses the DataGridView.DefaultCellStyle property to set the wrap mode for the entire control.

this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;