Custom datagrid column

  • Thread starter Thread starter VC
  • Start date Start date
V

VC

Hi, could someone points me to a article, whitepaper or other about
how to create a simple custimized column for a (2008 .net)
DataGridView windows form control?

I've saw a lot of sample over the internet but all of them too much
complicated. I just need something simple since I'm a begginer in C#.

Thanks in advance.
 
Not sure where an example would be online, but here's a technique that I use:

Create a DataTable with the columns you are interested in. Fill all of your
rows using the logic you created the columns with, then add the DataTable to
your DataGridView control.

EXAMPLE:
// Start Example Code:
DataTable table = new DataTable();
DataColumn col1 = table.Columns.Add("Col 1 Int32",
Type.GetType("System.Int32"));
DataColumn col2 = table.Columns.Add("Col 2 String",
Type.GetType("System.String"));
for (int i = 0; i < 5; i++) {
DataRow r = table.NewRow();
r[col1] = i;
r[col2] = string.Format("Data for {0}", i");
table.Rows.Add(r);
}
DataGridView1.DataSource = table.DefaultView;
// End of Example

If this isn't what you need, could you be a little more specific in your
question?
 
Hi

I 'd like to know how to create customized coluns on a DataGRidView.
In the past on VS2003, we were able to create coluns like
DataboundColunm, CheckBoxcolumn and so on. How do I create this kind
of columns in VC2008 datagridview now?

Or the unique way is creating customized columns on datatable and them
perform a dotabound?


Not sure where an example would be online, but here's a technique that I use:

Create a DataTable with the columns you are interested in. Fill all of your
rows using the logic you created the columns with, then add the DataTableto
your DataGridView control.

EXAMPLE:
// Start Example Code:
DataTable table = new DataTable();
DataColumn col1 = table.Columns.Add("Col 1 Int32",
Type.GetType("System.Int32"));
DataColumn col2 = table.Columns.Add("Col 2 String",
Type.GetType("System.String"));
for (int i = 0; i < 5; i++) {
  DataRow r = table.NewRow();
  r[col1] = i;
  r[col2] = string.Format("Data for {0}", i");
  table.Rows.Add(r);}

DataGridView1.DataSource = table.DefaultView;
// End of Example

If this isn't what you need, could you be a little more specific in your
question?

VC said:
Hi, could someone points me to a article, whitepaper or other about
how to create a simple custimized column for a (2008 .net)
DataGridView windows form control?
I've saw a lot of sample over the internet but all of them too much
complicated. I just need something simple since I'm a begginer in C#.
Thanks in advance.
 
Could you post some example code of what you did and how you did it in VS2003?

If a DataColumn is specified as a Bit field (Boolean), CheckBoxes should
still show up whenever you include the DataTable containing the DataColumn to
your DataGridView.

VC said:
Hi

I 'd like to know how to create customized coluns on a DataGRidView.
In the past on VS2003, we were able to create coluns like
DataboundColunm, CheckBoxcolumn and so on. How do I create this kind
of columns in VC2008 datagridview now?

Or the unique way is creating customized columns on datatable and them
perform a dotabound?


Not sure where an example would be online, but here's a technique that I use:

Create a DataTable with the columns you are interested in. Fill all of your
rows using the logic you created the columns with, then add the DataTable to
your DataGridView control.

EXAMPLE:
// Start Example Code:
DataTable table = new DataTable();
DataColumn col1 = table.Columns.Add("Col 1 Int32",
Type.GetType("System.Int32"));
DataColumn col2 = table.Columns.Add("Col 2 String",
Type.GetType("System.String"));
for (int i = 0; i < 5; i++) {
DataRow r = table.NewRow();
r[col1] = i;
r[col2] = string.Format("Data for {0}", i");
table.Rows.Add(r);}

DataGridView1.DataSource = table.DefaultView;
// End of Example

If this isn't what you need, could you be a little more specific in your
question?

VC said:
Hi, could someone points me to a article, whitepaper or other about
how to create a simple custimized column for a (2008 .net)
DataGridView windows form control?
I've saw a lot of sample over the internet but all of them too much
complicated. I just need something simple since I'm a begginer in C#.
Thanks in advance.
 
Back
Top