473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

dynamic column/fields

ER
Hi,

I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?

Any help would be appreciated!

ER
Jan 7 '06 #1
3 1368
The datagrid server control provides a property named AutoGenerateColumns
that would allow the grid to display any number of columns that are on the
datatable.
http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

You can make the datagrid editable by adding an EditCommandColumn
http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx

Another alternative is to turn the AutoGenerateColumns to false and then
compose the columns programmatically during databinding like this:
private void dgItems_DataBinding(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgItems.DataSource;
for( int c=1; c<dt.Columns.Count; c++ )
{
BoundColumn bc = new BoundColumn();
bc.DataField = dt.Columns[c].ColumnName;
bc.HeaderText = dt.Columns[c].ColumnName;
dgItems.Columns.Add( bc );
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"ER" wrote:
Hi,

I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?

Any help would be appreciated!

ER

Jan 7 '06 #2
ER
Thanks Phillip. For the second solution, would that affect the performance if
the datagrid has significant data to display?

Thanks,
ER

"Phillip Williams" wrote:
The datagrid server control provides a property named AutoGenerateColumns
that would allow the grid to display any number of columns that are on the
datatable.
http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

You can make the datagrid editable by adding an EditCommandColumn
http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx

Another alternative is to turn the AutoGenerateColumns to false and then
compose the columns programmatically during databinding like this:
private void dgItems_DataBinding(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgItems.DataSource;
for( int c=1; c<dt.Columns.Count; c++ )
{
BoundColumn bc = new BoundColumn();
bc.DataField = dt.Columns[c].ColumnName;
bc.HeaderText = dt.Columns[c].ColumnName;
dgItems.Columns.Add( bc );
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"ER" wrote:
Hi,

I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?

Any help would be appreciated!

ER

Jan 9 '06 #3
I think that the performance would be the same.

If the only requirement in building the datagrid were to display all columns
without exception, such as the sample code below, then I prefer using the
declarative syntax (the first solution) because it makes the code more
readable and easily maintainable (one can change it without recompiling the
application).

If, on the other hand, one has to use different conditions for columns that
may or may not be provided in the data or if one has to hide particular
columns if they happen to exist in the data then the second approach would
work better.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"ER" wrote:
Thanks Phillip. For the second solution, would that affect the performance if
the datagrid has significant data to display?

Thanks,
ER

"Phillip Williams" wrote:
The datagrid server control provides a property named AutoGenerateColumns
that would allow the grid to display any number of columns that are on the
datatable.
http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

You can make the datagrid editable by adding an EditCommandColumn
http://msdn2.microsoft.com/en-us/lib...andcolumn.aspx

Another alternative is to turn the AutoGenerateColumns to false and then
compose the columns programmatically during databinding like this:
private void dgItems_DataBinding(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgItems.DataSource;
for( int c=1; c<dt.Columns.Count; c++ )
{
BoundColumn bc = new BoundColumn();
bc.DataField = dt.Columns[c].ColumnName;
bc.HeaderText = dt.Columns[c].ColumnName;
dgItems.Columns.Add( bc );
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"ER" wrote:
Hi,

I would like to create a datagrid or free entry form with dynamic columns
based on the user selection, do you have any ideas or samples?

Any help would be appreciated!

ER

Jan 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Drew | last post by:
I am trying to build a small app that shows a Course Title from the database, then displays a dropdown full of categories for the user to choose one... I thought a loop would be the best way to...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: CSDunn | last post by:
Hello, I have a format issue on an Access 2000 ADP report that I am going to attempt to explain from a 'ten thousand foot view' : I have an Access 2000 ADP report that has a SQL Server 2000...
1
by: Richard Hollenbeck | last post by:
Hello Newsgroup. You have all been very helpful in the past and I thank you. I try to ask relevant questions so that they don't just benefit me, but also benefit the group. I'm currently...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: Bongard | last post by:
I have a dynamic range that I would like to use as a linked table into Access. The problem is that Access doesn't seem to want to to recognize the dynamic range when you click on "show named...
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.