Click here to Skip to main content
15,888,816 members
Articles / Programming Languages / C#
Article

ComboBox in a DataGrid

Rate me:
Please Sign up or sign in to vote.
3.38/5 (37 votes)
13 Sep 2006CPOL3 min read 483K   6.6K   84   60
How to embed a ComboBox (DropDownList) in a DataGrid.

Introduction

I needed a ComboBox in my DataGrid. After looking around on the web, I found many examples, but none of them worked for me.

With inspiration from Alastair Stells' article here on The Code Project and whatever else I found on the Internet, I have made the following DataGridComboBoxColumn class.

Why did the other examples not work

All the other examples populate the ComboBox with a DataView, but I need to (want to be able to) populate my ComboBox with an IList (ArrayList) instead of a DataView.

C#
columnComboBox = new DataGridComboBoxColumn();
columnComboBox.comboBox.DataSource = new ArrayList(MyDataClass.GetArray());
columnComboBox.comboBox.DisplayMember = "Name";
columnComboBox.comboBox.ValueMember = "GUID";

And MyDataClass.GetArray() returns MyDataClass[], and has two properties named Name and GUID.

The other examples expect columnComboBox.comboBox.DataSource to be a DataView, and it being an ArrayList generates exceptions.

I use the ComboBox to fetch display text

Since you don't know the type of columnComboBox.comboBox.DataSource, you can't use that to translate between the underlying data and what to display in the DataGrid.

Instead, I use the ComboBox itself, by overriding the ComboBox and implementing this method.

C#
public string GetDisplayText(object value) {
   // Get the text.
   string text   = string.Empty;
   int  memIndex  = -1;
   try {
      base.BeginUpdate();
      memIndex     = base.SelectedIndex;
      base.SelectedValue = value.ToString();
      text      = base.SelectedItem.ToString();
      base.SelectedIndex = memIndex;
   } catch {
     return GetValueText(0);
   } finally {
      base.EndUpdate();
   }

   return text;
} // GetDisplayText

What I do is simple. I select the item which displays the text I want, get the text, and then reselect the original item. By doing it this way, it doesn't matter what data source is used.

Because I use the ComboBox itself to fetch the display text, the ComboBox must be populated before the DataGrid is drawn.

Alastair Stells noted about this in his article:

Another issue which arose was an eye-opener! I discovered the ComboBox does not get populated until the ComboBox.Visible property is set for the first time.

This means that the ComboBox can't be used to fetch the initial display text, because it is not visible when the DataGrid is first shown (painted).

I used a normal ComboBox to illustrate the problem and the solution.

C#
ComboBox comboBox = new ComboBox();
comboBox.DataSource = new ArrayList(MyDataClass.GetArray());
comboBox.DisplayMember = "Name"
comboBox.ValueMember = "GUID"
MessageBox.Show(comboBox.Items.Count.ToString()); // THIS IS ALWAYS 0!

I learned that it didn't help to show the ComboBox, but instead I had to set its parent - which internally commits the data from the DataSource to the Items collection.

C#
ComboBox comboBox = new ComboBox();
comboBox.Parent = this; // this is a Form instance in my case.
comboBox.DataSource = new ArrayList(MyDataClass.GetArray());
comboBox.DisplayMember = "Name"
comboBox.ValueMember = "GUID"
// THIS IS MyDataClass.GetArray().Count
MessageBox.Show(comboBox.Items.Count.ToString());

What else about my DataGridComboBoxColumn

The source code is straightforward. First, I inherited DataGridTextBoxColumn, but my class then evolved into inheriting DataGridColumnStyle. This meant that I had to implement the Paint methods, but at this point, I had some examples of that as well. I like the idea of not having an invisible TextBox behind it all.

How to use

Sadly, I don't know how to "register" my DataGridComboBoxColumn with the GridColumnStyles, enabling me to design the DataGrid columns in the designer. This code does it manually:

C#
// Add three MyDataClass objects, to the DataGridComboBox.
// This is the choices which will apear in the ComboBox in the DataGrid.
// You can see in the source that the MyDataClass doubles
// as a static collection, where the new MyDataClass objects
// automatically is added.
// All the MyDataClass objects can be retreived in an array
// with the static method: MyDataClass.GetArray().
if (MyDataClass.GetArray().Length == 0) {
    new MyDataClass("Denmark");
    new MyDataClass("Faroe Islands (DK)");
    new MyDataClass("Finland");
    new MyDataClass("Greenland (DK)");
    new MyDataClass("Iceland");
    new MyDataClass("Norway");
    new MyDataClass("Sweden");
}


// I don't have a database here, so I make my
// own DataTable with two columns and finally
// populate it with some test rows.
DataTable table = new DataTable("TableOne");

DataColumn column = table.Columns.Add();
column.ColumnName = "country";
// Realy a GUID from the DataGridComboBox.
column.DataType = Type.GetType("System.Guid");

column = table.Columns.Add();
column.ColumnName = "notes";
column.DataType = Type.GetType("System.String");

table.Rows.Add(new object[] {MyDataClass.GetArray()[0].GUID, 
                             "Population 5.368.854"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[1].GUID, 
                             "Population 46.011"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[2].GUID, 
                             "Population 5.183.545"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[3].GUID, 
                             "Population 56.376"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[4].GUID, 
                             "Population 279.384"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[5].GUID, 
                             "Population 4.525.116"});
table.Rows.Add(new object[] {MyDataClass.GetArray()[6].GUID, 
                             "Population 8.876.744"});

// Create a DataGridTableStyle object.
DataGridTableStyle tableStyle = new DataGridTableStyle();
DataGridTextBoxColumn columnTextBox;
DataGridComboBoxColumn columnComboBox;
tableStyle.RowHeadersVisible = true;
tableStyle.RowHeaderWidth = 20;

// Add customized columns.
// Column "notes", which is a simple text box.
columnTextBox = new DataGridTextBoxColumn();
columnTextBox.MappingName = "notes";
columnTextBox.HeaderText = "Country notes";
columnTextBox.Width = 200;
tableStyle.GridColumnStyles.Add(columnTextBox);

// Column "country", which is the ComboBox.
columnComboBox = new DataGridComboBoxColumn();
columnComboBox.comboBox.Parent = this; // Commit dataset.
columnComboBox.comboBox.DataSource = 
               new ArrayList(MyDataClass.GetArray());
columnComboBox.comboBox.DisplayMember = "name";
columnComboBox.comboBox.ValueMember = "GUID";
columnComboBox.MappingName = "country";
columnComboBox.HeaderText = "Country";
columnComboBox.Width = 200;
tableStyle.GridColumnStyles.Add(columnComboBox);

// Add the custom TableStyle to the DataGrid.
datagrid.TableStyles.Clear();
datagrid.TableStyles.Add(tableStyle);
datagrid.DataSource = table;
tableStyle.MappingName = "TableOne";

I think I have focused on a problem here: if you want a ComboBox in your DataGrid, and you want to populate the ComboBox with items from an array containing instances of your own class.

I hope someone finds it useful - enjoy.

Updated September 2006

A few bugs have been found in my source code. Apparently, someone still downloads and tries to use the source, even though .NET 2.0 has solved the problem with a ComboBox in a DataGrid. The new download contains the original source, plus a small VS project with the updated source code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems / Hardware Administrator
Denmark Denmark
See https://rpc-scandinavia.dk/

Comments and Discussions

 
QuestionCan i use this with real database? Pin
estrangeiro26-Sep-04 10:09
estrangeiro26-Sep-04 10:09 
GeneralGrid scrolling problem Pin
CP user25-Aug-04 11:22
CP user25-Aug-04 11:22 
GeneralRe: Grid scrolling problem Pin
bilberry717-Mar-05 23:06
bilberry717-Mar-05 23:06 
GeneralVS 2003 Designer compatibility Pin
Thosmos23-Jul-04 13:17
Thosmos23-Jul-04 13:17 
Generalcombobox display value when not focused Pin
Member 120742729-Jun-04 14:41
Member 120742729-Jun-04 14:41 
GeneralRe: combobox display value when not focused Pin
René Paw Christensen2-Jul-04 13:43
René Paw Christensen2-Jul-04 13:43 
GeneralRe: combobox display value when not focused Pin
marcellusc8-Jul-04 3:46
marcellusc8-Jul-04 3:46 
GeneralRe: combobox display value when not focused Pin
René Paw Christensen8-Jul-04 12:19
René Paw Christensen8-Jul-04 12:19 
Hi Marcellusc.

It is true there only is one DataGridComboBox object at a time. It is hidden when none of the cells in the column is being edited. When needed, it is positioned accordingly and shown.

When the DataGridComboBox is not needed, the text is drawn directly - by the Paint method.

I have been looking at the code, and discovered some errors. Basicly it has something to do with types, and a couple of the ToString() calls.

Condition: The data choosen in the ComboBox must be of the same type as the corrosponding data in the DataGrids data source.

In the example code below, the data in the ComboBox (ValueMember) is a GUID, and the corrosponding column in the DataTable which is the DataGrids data source, is also a GUID.

I think I made the error, because I used some old code to fill my ComboBox, which filled it with strings insted of GUIDs.

It is late, and I will be happy to talk more about this in the days to come - if for instance I have not made my self clear. Anyway I will leave you with my test code (Form1.cs) for now.

---------- BEGIN FORM1.CS ----------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Test {

//**********************************************************************************************
// Form1
//**********************************************************************************************
public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid datagrid;
private System.ComponentModel.Container components = null;

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent() {
this.datagrid = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.datagrid)).BeginInit();
this.SuspendLayout();
//
// datagrid
//
this.datagrid.DataMember = "";
this.datagrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.datagrid.Location = new System.Drawing.Point(8, 8);
this.datagrid.Name = "datagrid";
this.datagrid.Size = new System.Drawing.Size(472, 200);
this.datagrid.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(400, 224);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Populate";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(492, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.datagrid);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.datagrid)).EndInit();
this.ResumeLayout(false);

}
#endregion

#region Constructor and destructor
public Form1() {
InitializeComponent();
} // Form1

protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
} // Dispose

[STAThread]
static void Main() {
Application.Run(new Form1());
} // Main
#endregion

private void button1_Click(object sender, System.EventArgs e) {
// I don't have a database here, so I make my own DataTable.
DataTable table = new DataTable("TableOne");

DataColumn column = table.Columns.Add();
column.ColumnName = "country";
column.DataType = Type.GetType("System.Guid"); // Realy a GUID from the DataGridComboBox.

column = table.Columns.Add();
column.ColumnName = "notes";
column.DataType = Type.GetType("System.String");


// Add three MyDataClass objects, to the DataGridComboBox.
new MyDataClass("Norway");
new MyDataClass("Denmark");
new MyDataClass("Sweden");

table.Rows.Add(new object[2] {MyDataClass.GetArray()[1].GUID, "Description about Denmark."});

// Create a DataGridTableStyle object.
DataGridTableStyle tableStyle = new DataGridTableStyle();
DataGridTextBoxColumn columnTextBox;
DataGridComboBoxColumn columnComboBox;
tableStyle.RowHeadersVisible = true;
tableStyle.RowHeaderWidth = 20;

// Add customized columns.
columnTextBox = new DataGridTextBoxColumn();
columnTextBox.MappingName = "notes";
columnTextBox.HeaderText = "Country notes";
columnTextBox.Width = 200;
tableStyle.GridColumnStyles.Add(columnTextBox);

columnComboBox = new DataGridComboBoxColumn();
columnComboBox.comboBox.Parent = this; // Commit dataset.
columnComboBox.comboBox.DataSource = new ArrayList(MyDataClass.GetArray());
columnComboBox.comboBox.DisplayMember = "name";
columnComboBox.comboBox.ValueMember = "GUID";
columnComboBox.MappingName = "country";
columnComboBox.HeaderText = "Country";
columnComboBox.Width = 200;
tableStyle.GridColumnStyles.Add(columnComboBox);

// Add the custom TableStyle to the DataGrid.
datagrid.TableStyles.Clear();
datagrid.TableStyles.Add(tableStyle);
datagrid.DataSource = table;
tableStyle.MappingName = "TableOne";

} // button1_Click

} // Form1

#region MyDataClass
//**********************************************************************************************
// MyDataClass
//**********************************************************************************************
public class MyDataClass {
private static ArrayList myDataClasses = new ArrayList();
private Guid myGuid;
private string myName;

public MyDataClass(string name) {
myGuid = Guid.NewGuid();
myName = name;
myDataClasses.Add(this);
} // MyDataClass

public Guid GUID {
get {
return myGuid;
}
} // GUID

public string name {
get {
return myName;
}
set {
myName = value;
}
} // name

public static MyDataClass[] GetArray() {
MyDataClass[] objects = new MyDataClass[myDataClasses.Count];
int index = 0;
foreach (MyDataClass item in myDataClasses) {
objects[index] = item;
index++;
}
return objects;
} // GetArray

} // MyDataClass
#endregion

#region DataGridComboBoxColumn
//**********************************************************************************************
// DataGridTextBoxColumn
//**********************************************************************************************
public class DataGridComboBoxColumn : DataGridColumnStyle { //DataGridTextBoxColumn {
private DataGridComboBox combobox;
private bool edit;

//-------------------------------------------------------------------------------------------
// Constructors and destructors
//-------------------------------------------------------------------------------------------
public DataGridComboBoxColumn() {
combobox = new DataGridComboBox();
combobox.Visible = false;
combobox.DropDownStyle = ComboBoxStyle.DropDownList;
combobox.Leave += new EventHandler(ComboHide);
combobox.SelectionChangeCommitted += new EventHandler(ComboStartEditing);
edit = false;
} // DataGridComboBoxColumn

//-------------------------------------------------------------------------------------------
// Properties
//-------------------------------------------------------------------------------------------
public ComboBox comboBox {
get {
return combobox;
}
} // comboBox

//-------------------------------------------------------------------------------------------
// ComboBox event handlers
//-------------------------------------------------------------------------------------------
private void ComboHide(object sender, EventArgs e) {
// When the ComboBox looses focus, then simply hide it.
combobox.Hide();
} // ComboHide

private void ComboStartEditing(object sender, EventArgs e) {
// Enter edit mode.
edit = true;
base.ColumnStartedEditing((Control)sender);
} // ComboStartEditing

//-------------------------------------------------------------------------------------------
// Override DataGridColumnStyle
//-------------------------------------------------------------------------------------------
protected override void SetDataGridInColumn(DataGrid value) {
// Add the ComboBox to the DataGrids controls collection.
// This ensures correct DataGrid scrolling.
value.Controls.Add(combobox);
base.SetDataGridInColumn(value);
} // SetDataGridInColumn

protected override void Abort(int rowNum) {
// Abort edit mode, discard changes and hide the ComboBox.
edit = false;
Invalidate();
combobox.Hide();
} // Abort

protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) {
// Setup the ComboBox for action.
// This includes positioning the ComboBox and showing it.
// Also select the correct item in the ComboBox before it is shown.
combobox.Parent = this.DataGridTableStyle.DataGrid;
combobox.Bounds = bounds;
combobox.Size = new Size(this.Width, this.comboBox.Height);
comboBox.SelectedValue = base.GetColumnValueAtRow(source, rowNum);//.ToString();
combobox.Visible = (cellIsVisible == true) && (readOnly == false);
combobox.BringToFront();
combobox.Focus();
} // Edit

protected override bool Commit(System.Windows.Forms.CurrencyManager source, int rowNum) {
// Commit the selected value from the ComboBox to the DataGrid.
if (edit == true) {
edit = false;
this.SetColumnValueAtRow(source, rowNum, combobox.SelectedValue);
}

return true;
} // Commit

protected override object GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum) {
// Return the display text associated with the data, insted of the
// data from the DataGrid datasource.
return combobox.GetDisplayText(base.GetColumnValueAtRow(source, rowNum));
} // GetColumnValueAtRow

protected override void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) {
// Save the data (value) to the DataGrid datasource.
// I try a few different types, because I often uses GUIDs as keys in my
// data.

// String.
// try {
// base.SetColumnValueAtRow(source, rowNum, value.ToString());
// return;
// } catch {}

// Guid.
// try {
// base.SetColumnValueAtRow(source, rowNum, new Guid(value.ToString()));
// return;
// } catch {}

// Object (default).
base.SetColumnValueAtRow(source, rowNum, value);
} // SetColumnValueAtRow

protected override int GetMinimumHeight() {
// Return the ComboBox preferred height, plus a few pixels.
return combobox.PreferredHeight + 2;
} // GetMinimumHeight

protected override int GetPreferredHeight(Graphics g, object val) {
// Return the font height, plus a few pixels.
return FontHeight + 2;
} // GetPreferredHeight

protected override Size GetPreferredSize(Graphics g, object val) {
// Return the preferred width.
// Iterate through all display texts in the dropdown, and measure each
// text width.
int widest = 0;
SizeF stringSize = new SizeF(0, 0);
foreach (string text in combobox.GetDisplayText()) {
stringSize = g.MeasureString(text, base.DataGridTableStyle.DataGrid.Font);
if (stringSize.Width > widest) {
widest = (int)Math.Ceiling(stringSize.Width);
}
}

return new Size(widest + 25, combobox.PreferredHeight + 2);
} // GetPreferredSize

protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) {
Paint(g, bounds, source, rowNum, false);
} // Paint

protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) {
string text = GetColumnValueAtRow(source, rowNum).ToString();
Brush backBrush = new SolidBrush(base.DataGridTableStyle.BackColor);
Brush foreBrush = new SolidBrush(base.DataGridTableStyle.ForeColor);
Rectangle rect = bounds;
StringFormat format = new StringFormat();

// Handle that the row can be selected.
if (base.DataGridTableStyle.DataGrid.IsSelected(rowNum) == true) {
backBrush = new SolidBrush(base.DataGridTableStyle.SelectionBackColor);
foreBrush = new SolidBrush(base.DataGridTableStyle.SelectionForeColor);
}

// Handle align to right.
if (alignToRight == true) {
format.FormatFlags = StringFormatFlags.DirectionRightToLeft;
}

// Handle alignment.
switch (this.Alignment) {
case HorizontalAlignment.Left:
format.Alignment = StringAlignment.Near;
break;
case HorizontalAlignment.Right:
format.Alignment = StringAlignment.Far;
break;
case HorizontalAlignment.Center:
format.Alignment = StringAlignment.Center;
break;
}

// Paint.
format.FormatFlags = StringFormatFlags.NoWrap;
g.FillRectangle(backBrush, rect);
rect.Offset(0, 2);
rect.Height -= 2;
g.DrawString(text, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect, format);
format.Dispose();
} // PaintText

} // DataGridComboBoxColumn
#endregion

#region DataGridComboBox
//**********************************************************************************************
// DataGridComboBox
//**********************************************************************************************
public class DataGridComboBox : ComboBox {
private const int WM_KEYUP = 0x101;

protected override void WndProc(ref System.Windows.Forms.Message message) {
// Ignore keyup to avoid problem with tabbing and dropdown list.
if (message.Msg == WM_KEYUP) {
return;
}

base.WndProc(ref message);
} // WndProc

public string GetValueText(int index) {
// Validate the index.
if ((index < 0) && (index >= base.Items.Count))
throw new IndexOutOfRangeException("Invalid index.");

// Get the text.
string text = string.Empty;
int memIndex = -1;
try {
base.BeginUpdate();
memIndex = base.SelectedIndex;
base.SelectedIndex = index;
text = base.SelectedValue.ToString();
base.SelectedIndex = memIndex;
} catch {
} finally {
base.EndUpdate();
}

return text;
} // GetValueText

public string GetDisplayText(int index) {
// Validate the index.
if ((index < 0) && (index >= base.Items.Count))
throw new IndexOutOfRangeException("Invalid index.");

// Get the text.
string text = string.Empty;
int memIndex = -1;
try {
base.BeginUpdate();
memIndex = base.SelectedIndex;
base.SelectedIndex = index;
text = base.SelectedItem.GetType().GetProperty(base.DisplayMember).GetValue(base.SelectedItem, new object[0]).ToString();
base.SelectedIndex = memIndex;
} catch {
} finally {
base.EndUpdate();
}

return text;
} // GetDisplayText

public string GetDisplayText(object value) {
// Get the text.
string text = string.Empty;
int memIndex = -1;
try {
base.BeginUpdate();
memIndex = base.SelectedIndex;
base.SelectedValue = value;//.ToString();
text = base.SelectedItem.GetType().GetProperty(base.DisplayMember).GetValue(base.SelectedItem, new object[0]).ToString();
base.SelectedIndex = memIndex;
} catch {
} finally {
base.EndUpdate();
}

return text;
} // GetDisplayText

public string[] GetDisplayText() {
// Get the text.
string[] text = new string[base.Items.Count];
int memIndex = -1;
try {
base.BeginUpdate();
memIndex = base.SelectedIndex;
for (int index = 0; index < base.Items.Count; index++) {
base.SelectedIndex = index;
text[index] = base.SelectedItem.GetType().GetProperty(base.DisplayMember).GetValue(base.SelectedItem, new object[0]).ToString();
}
base.SelectedIndex = memIndex;
} catch {
} finally {
base.EndUpdate();
}

return text;
} // GetDisplayText

} // DataGridComboBox
#endregion

} // Test

---------- END FORM1.CS ----------


Live Long and Prosper
René Paw Christensen
GeneralDisplay 'System.Data.DataRowView' Pin
Lucky Vdb16-Jun-04 1:27
professionalLucky Vdb16-Jun-04 1:27 
GeneralRe: Display 'System.Data.DataRowView' Pin
Lucky Vdb16-Jun-04 2:12
professionalLucky Vdb16-Jun-04 2:12 
GeneralRe: Display 'System.Data.DataRowView' Pin
René Paw Christensen16-Jun-04 11:50
René Paw Christensen16-Jun-04 11:50 
GeneralRe: Display 'System.Data.DataRowView' Pin
cphaluss18-Jan-05 18:47
cphaluss18-Jan-05 18:47 
QuestionI could not make it works at all. Who can help it for me? Pin
anhnn10-Jun-04 0:02
anhnn10-Jun-04 0:02 
AnswerRe: I could not make it works at all. Who can help it for me? Pin
René Paw Christensen10-Jun-04 11:00
René Paw Christensen10-Jun-04 11:00 
Generalcreating an ArrayList Pin
EL HACHIMI9-Jun-04 0:38
EL HACHIMI9-Jun-04 0:38 
GeneralRe: creating an ArrayList Pin
René Paw Christensen9-Jun-04 11:32
René Paw Christensen9-Jun-04 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.