Working with the mmDataGridView
The MM .NET Windows Forms mmDataGridView class is a direct subclass of the DataGridView control which is new in .NET 2.0 Windows Forms. Here are some commonly used properties and events:
| Member | Description |
|---|---|
| AllowUserToAddRows | Specifies if users can add new rows by pressing the down arrow. Set to false by default in mmDataGridView so the business object is not bypassed when adding new rows |
| AllowUserToDeleteRows | Specifies if users can delete rows by pressing the delete key. Set to false by default in mmDataGridView so the business object is not bypassed when deleting rows. |
| AutoSizeColumnsMode | Specifies the auto size mode for visible columns. Can be set to:
|
| BackgroundColor | Normally you should set this to White. By default, the background color of the DataGridView is set to AppWorkSpace (usually dark grey). If your grid is only partially filled with rows, the dark grey is displayed in the blank area and doesn't look very professional. You can set the background color to White by selecting the BackgroundColor's Custom tab and selecting white from the color palette. |
| MultiSelect | Specifies if the user can select multiple rows |
| RowHeadersVisible | Specifies if row headers (a rectangular selection box at the left of each row) are visible |
| SelectRows | Contains the rows selected by the user |
| SelectionMode | Specifies how the cells of the DataGridView are selected. Possible values are:
|
| CurrentRow | Returns the current row in the DataGrid. Check out the section below that desribes custom MM .NET methods GetCurrentRow(), GetCurrentRowPK() and GetCurrentRowPKs() which give more information about the current row |
| SelectionChanged event | Occurs when the current selection changes |
| RowEnter event | Fires when a row is changed and replaces the mmDataGrid.RowChanged event |
Data Binding mmDataGridView
In the Properties Window, select the BindingSource property. Click the ellipses button [...] next to the property which launches the Binding Source Selection dialog. Select the business object you want to bind the mmDataGridView to from the list and click OK. For example:
This stores the business object name in the mmDataGridView's BindingSource property.
If you don't specify any other binding properties, the mmDataGridView is bound to the business object's default DataTable (specified in the business object's TableName) property. If you want to bind the mmDataGridView to a different table, specify the table name in the mmDataGridView's BindingSourceMember property. For example, if you want to bind the mmDataGridView to a table named UserRoles, you would set the BindingSourceMember property as follows:

Alternately, you can bind the mmDataGridView to a DataView associated with a given table. To do this, specify the name of the table and data view (separated by a period) in the mmDataGridView's BindingSourceMember property. For example, if you want to bind the mmDataGridView to a DataView named dvUserRoles associated with the Roles table, you would set the BindingSourceMember property as follows:

Setting up Columns in mmDataGridView
You can use the standard Visual Studio builders to set up columns in mmDataGridView. The following instructions outline the steps you must take to do this.- In design mode, right-click the DataGridView and select Edit Columns from the shortcut menu (alternately you can click the DataGridView's Smart Tag and select Edit Columns).
- Click the Add... button to add a new column to the DataGridView. This launches the Add Column dialog:

- In the Name text box, change the name of the column to something descriptive of its contents. In the Type combo box, select the type of control you want to add to the new column, and in the Header text box enter the text you want to display for the column at run time.
- You can also set other properties of the column such as Visible, Read Only, and Frozen. Check out the Visual Studio Help for information on setting these properties.
- Click Add to close the Add Column dialog and add the new colum to the DataGridView.
In the Edit Columns dialog, change the DataPropertyName property to the name of the data column you want to bind to at run time:

- When you have finished adding columns to the DataGridView, click OK to close the Edit Columns dialog.
- To specify that only the columns you have specified are displayed at run time, you must set the DataGridView's AutoGenerateColumns property to false. Unfortunately, this property is not visible in the property sheet! You have to add code to your form's constructor to set this property to false.
For example, in C#:
public MyForm() InitializeComponent(); this.grdMappings.AutoGenerateColumns = false; }
And in VB .NET:
Public Sub New() InitializeComponent() Me.grdMappings.AutoGenerateColumns = False End Sub
Adding Combo Box Columns to the DataGridView
Note: For a live example of a combo box column in a DataGridView, see the MM .NET Windows Forms sample application Customer Orders Form Order Details DataGridView.
Follow these steps to add a ComboBox column to a DataGridView
- Right-click your DataGridView in design mode and select Edit Columns from the shortcut menu.
- In the Edit Columns dialog, click the Add button which launches the Add Column dialog. In the Name textbox, specify the name of the column, in the Type column, select DataGridViewComboBoxColumn, specify the Header Text, then click Add, then Close. For example:

- In the Edit Columns dialog, set the DataPropertyName property to the column in the DataGridView's data source that sets the currently selected item in the combo box. Click OK to close the dialog.
- In the form's constructor, add code that retrieves the list of items to be displayed in the combo box and binds the data to the combo box's DataSource, DisplayMember, and ValueMember properties. Create a form-level variable to hold the DataTable or DataSet used as the data source for the combo box. For example:
protected DataTable dtProducts; protected DataGridViewComboBoxColumn ProductColumn; // auto-generated by the WinForms designer /// <summary> /// Constructor /// </summary> public CustomerOrdersForm() { /// Instantiate and register business objects this.oProduct = (Product)this.RegisterBizObj(new Product()); // // Required for Windows Form Designer support // InitializeComponent(); dtProducts = this.oProduct.GetAllData(); this.ProductColumn.DataSource = dtProducts; this.ProductColumn.DisplayMember = "ProductName"; this.ProductColumn.ValueMember = "ProductID"; }
When your DataGridView displays at run time, the combo box column should be populated with items from your combo box data source and the currently selected item should be set based on the value of the underlying DataGridView data source.
Specifying the DataGridView as the Form's Primary Navigation Control
To specify the DataGridView as your form's primary navigation control set the form's NavControl property accordingly in the form's constructor.For example, in C#:
this.NavControl = this.grdRoles;And in VB .NET:
Me.NavControl = Me.grdRolesMaking mmDataGridView Read Only
To make mmDataGridView read-only, set the following properties:AutoSetEnabled = False
ReadOnly = True
Retrieving Current Row Information
The mmDataGrid class has the following methods that allow you to retrieve information about the currently selected row in the DataGrid.- GetCurrentRow - Returns the current row in the grid, as well as the associated business object as an output parameter.
- GetCurrentRowPK - Returns the primary key value of the currently selected row. Used with data sources that have a single primary key field.
- GetCurrentRowPKs - Returns the primary key values of the currently selected row. Used with data sources that have multiple primary key fields.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/27/18
Comment or report problem with topic
