Home / Community & Support / Knowledge Base / RadControls for WinForms / GridView / Create MultiColumnListBox based on RadGridView

Create MultiColumnListBox based on RadGridView

Article Info

Rating: 4

Article information

Article relates to

 RadControls for WinForms Q2 2010 SP2

Created by

 Nikolay Diyanov

Last modified

 Oct 5, 2010

Last modified by

 Nikolay Diyanov



HOW-TO

Create MultiColumnListBox based on RadGridView.

SOLUTION

In order to make RadGridView look like a (MultiColumn) ListBox, you just need to set a small number of properties. This will allow you to have a listbox-like view, but you will still be able to use all the features that RadGridView supports.

Let's have three columns - a checkbox column and two text columns. The properties that we should set are these:
this.radGridView1.ShowGroupPanel = false;
this.radGridView1.MasterTemplate.ShowColumnHeaders = false;
this.radGridView1.MasterTemplate.AllowAddNewRow = false;
this.radGridView1.MasterTemplate.ShowRowHeaderColumn = false;
this.radGridView1.MasterTemplate.BestFitColumns();
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

Now in order to hide the border in RadGridView, simply subscribe for the CellFormatting event, and set the DrawFill property:
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    e.CellElement.DrawBorder = false;
}

Optionally, we can set the ReadOnly property of the text columns, since the in general listbox controls are not editable:
this.radGridView1.Columns[1].ReadOnly = true;
this.radGridView1.Columns[2].ReadOnly = true;

The result is shown on the screenshot below:

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.