Example E3354
Visible to All Users

WinForms Data Grid - How to create and populate an unbound column

This example demonstrates how to:

Files to Review

Tutorial Video

Documentation

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

WindowsApplication1/Form1.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraGrid.Columns; namespace WindowsApplication1 { public partial class Form1 : Form { private DataColumn _KeyField; private DataTable _Tbl; private MyCache _Cache = new MyCache("ID"); private DataTable CreateTable(int RowCount) { _Tbl = new DataTable(); _KeyField = _Tbl.Columns.Add("ID", typeof(int)); _KeyField.ReadOnly = true; _KeyField.AutoIncrement = true; _Tbl.Columns.Add("Name", typeof(string)); _Tbl.Columns.Add("Number", typeof(int)); _Tbl.Columns.Add("Date", typeof(DateTime)); for (int i = 0; i < RowCount; i++) _Tbl.Rows.Add(new object[] { null, String.Format("Name{0}", i), 3 - i, DateTime.Now.AddDays(i) }); return _Tbl; } public Form1() { InitializeComponent(); gridControl1.DataSource = CreateTable(20); CreateUnboundColumn(); } private void CreateUnboundColumn() { GridColumn col = gridView1.Columns.AddVisible("Unbound", "Unbound column"); col.UnboundType = DevExpress.Data.UnboundColumnType.String; } private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { if (e.IsGetData) e.Value = _Cache.GetValue(e.Row); if (e.IsSetData) _Cache.SetValue(e.Row, e.Value); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.