Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mapping a column in my datagrid
Message
From
22/10/2007 07:30:17
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
18/10/2007 12:31:42
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01261886
Message ID:
01262501
Views:
15
>I have drop a grid on my form and visually added 3 columns.
>I am able to bind the grid. But I do not know how to bind/map the columns.
>
>I bind the grid like this :
>
>grdPolicyChangesNotes.DataSource = dsData;
>grdPolicyChangesNotes.DataMember = "PolicyNotes";
>
>
>
>How do I bound the columns to the specific fields on my dataset??.
>
>Thanks,
>sergiio

Here is a rough sample:
        private void BindMyColumns()
        {
            DataTable tbl = CreateData();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = tbl;
            DataGridViewTextBoxColumn colName = new DataGridViewTextBoxColumn();
            colName.HeaderText = "Name";
            colName.DataPropertyName = "col2";
            dataGridView1.Columns.Add(colName);
            DataGridViewCheckBoxColumn colBool = new DataGridViewCheckBoxColumn();
            colBool.HeaderText = "Column 4";
            colBool.DataPropertyName = "col4";
            dataGridView1.Columns.Add(colBool);
        }

        private DataTable CreateData()
        {
            DataTable tbl = new DataTable();
            tbl.Columns.Add("col1", typeof(int));
            tbl.Columns.Add("col2", typeof(string)); 
            tbl.Columns.Add("col3", typeof(DateTime));
            tbl.Columns.Add("col4", typeof(bool));
            for (int i = 0; i < 20; i++)
            {
                tbl.Rows.Add(new object[] 
               { i, String.Format("Name {0}", i), DateTime.Now.AddDays(-i), i % 2 == 0 });
            }
            return tbl;
        }
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform