473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Equivalent of DataGridTableStyle for DataGridView?

Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property and would use
the DataGrid's ability to switch between these sets of columns depending on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works. My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or am
I stuck with my current method of clearing and reloading the columns every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView and
DataGrid Controls" (http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.
Jul 28 '06 #1
7 12542
Hi,

Setting the Datagridview's AutoGenerateColumns property to false
will prevent the framework from adding the columns for you. There is not
any tablestyle property for the datagridview.

http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

Ken
-------------------
"Mitchell S. Honnert" <ne*@hRoEnMnOeVrEt.comwrote in message
news:uh**************@TK2MSFTNGP03.phx.gbl...
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one
with a custom set of columns) in the DataGrid.TableStyles property and
would use the DataGrid's ability to switch between these sets of columns
depending on the source data. You could say that the DataGrid's
DataGridTableStyle allowed you to have a set of "context sensitive"
columns. If the data changed, so too did the columns used to view the
data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever
I switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works.
My initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or
am I stuck with my current method of clearing and reloading the columns
every time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView
and DataGrid Controls"
(http://msdn2.microsoft.com/en-us/library/ms171628.aspx), it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.

Jul 29 '06 #2
Ken, I do use the AutoGenerateColumns property to prevent automatic column
loading, but my question was intended to focus more on the setting of custom
columns, especially on the possibility of switching between a predefined set
of custom columns in the DataGridView.

I understand that there is no DataGridViewTableStyle class which directly
corresponds to the DataGridTableStyle, but I was hoping there might be a
roughly similar feature in the DataGridView, albeit one that was implemented
using a different approach. The quote in the Microsoft documentation about
the DataGridView having all but one off the features of the DataGrid (see my
original post) made me think that the "switch between predefined set of
columns" feature was in the DataGridView *somewhere*; I just had to find it.

Thanks,

- Mitchell S. Honnert
"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:u3****************@TK2MSFTNGP02.phx.gbl...
Hi,

Setting the Datagridview's AutoGenerateColumns property to false
will prevent the framework from adding the columns for you. There is not
any tablestyle property for the datagridview.

http://msdn2.microsoft.com/en-us/lib...tecolumns.aspx

Ken
-------------------
"Mitchell S. Honnert" <ne*@hRoEnMnOeVrEt.comwrote in message
news:uh**************@TK2MSFTNGP03.phx.gbl...
>Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one
with a custom set of columns) in the DataGrid.TableStyles property and
would use the DataGrid's ability to switch between these sets of columns
depending on the source data. You could say that the DataGrid's
DataGridTableStyle allowed you to have a set of "context sensitive"
columns. If the data changed, so too did the columns used to view the
data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality,
whenever I switch the data source of my DataGridView, I have to clear out
the DataGridView.Columns and add the appropriate columns back. This
method works, but is far less elegant than the way that the old DataGrid
works. My initial idea was to store my sets of custom columns in
different DataGridViewColumnCollection instances and set the
DataGridView.Columns property as appropriate, but the
DataGridView.Columns is read-only, so I couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or
am I stuck with my current method of clearing and reloading the columns
every time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView
and DataGrid Controls"
(http://msdn2.microsoft.com/en-us/library/ms171628.aspx), it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.


Jul 29 '06 #3
Mitchell,

The DataGrid is still available in VS2005, why not continue to use it?

Kerry Moorman
"Mitchell S. Honnert" wrote:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property and would use
the DataGrid's ability to switch between these sets of columns depending on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works. My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or am
I stuck with my current method of clearing and reloading the columns every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView and
DataGrid Controls" (http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.
Jul 29 '06 #4
I thought about it, but there are just too many other improvements to the
DataGridView to warrant staying with the DataGrid. All in all, it's a good
trade-off. There's only one thing that I ran across that the DataGridView
can't do, and I have a workaround for that, so I don't regret the switch. I
just wanted to make sure I wasn't missing a "DataGridView way" of switching
between predefined column sets.

- Mitchell S. Honnert
"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:C3**********************************@microsof t.com...
Mitchell,

The DataGrid is still available in VS2005, why not continue to use it?

Kerry Moorman
"Mitchell S. Honnert" wrote:
>Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one
with
a custom set of columns) in the DataGrid.TableStyles property and would
use
the DataGrid's ability to switch between these sets of columns depending
on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality,
whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works.
My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or
am
I stuck with my current method of clearing and reloading the columns
every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView
and
DataGrid Controls"
(http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.

Jul 29 '06 #5

Mitchell S. Honnert wrote:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property and would use
the DataGrid's ability to switch between these sets of columns depending on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works. My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or am
I stuck with my current method of clearing and reloading the columns every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView and
DataGrid Controls" (http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.
The constructor for a DataGridViewColumnCollection requires the
DataGridView it is associated with. So, it cannot be held as instances.

However, as you are doing it, it can be cleared and refilled. Or, more
than one DataGridView can be used, Hide()ing and Show()ing them as
required.

B.

Jul 31 '06 #6
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Mitchell S. Honnert wrote:
>Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one
with
a custom set of columns) in the DataGrid.TableStyles property and would
use
the DataGrid's ability to switch between these sets of columns depending
on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality,
whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works.
My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or
am
I stuck with my current method of clearing and reloading the columns
every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView
and
DataGrid Controls"
(http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.

The constructor for a DataGridViewColumnCollection requires the
DataGridView it is associated with. So, it cannot be held as instances.

However, as you are doing it, it can be cleared and refilled. Or, more
than one DataGridView can be used, Hide()ing and Show()ing them as
required.

B.
Thanks Brian. I thought of the possibility of using different
DataGridViews, but one thing I didn't mention is that the underlying
DataTable is the same for each of my custom column sets. It just seemed
like overkill to have multiple DataGridViews just to support my different
column sets.

So, basically, it looks like I'll stick with my current solution of
reloading the columns when I need to switch the column set. I was hoping
that the DataGridView would have duplicated the DataGrid's
DataGridTableStyle functionality somehow, but it certainly looks like this
is not the case.

Thanks again,

- Mitchell S. Honnert
Jul 31 '06 #7
Mitchell S. Honnert wrote:
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...

Mitchell S. Honnert wrote:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?

Here's the background for my question...

Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one
with
a custom set of columns) in the DataGrid.TableStyles property and would
use
the DataGrid's ability to switch between these sets of columns depending
on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.

But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality,
whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works.
My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.

So, is there an easy way to assign a DataGridView columns in one step or
am
I stuck with my current method of clearing and reloading the columns
every
time?

Thanks,

- Mitchell S. Honnert

PS: In the MSDN page "Differences Between the Windows Forms DataGridView
and
DataGrid Controls"
(http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...

"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."

I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.
The constructor for a DataGridViewColumnCollection requires the
DataGridView it is associated with. So, it cannot be held as instances.

However, as you are doing it, it can be cleared and refilled. Or, more
than one DataGridView can be used, Hide()ing and Show()ing them as
required.

B.
Thanks Brian. I thought of the possibility of using different
DataGridViews, but one thing I didn't mention is that the underlying
DataTable is the same for each of my custom column sets. It just seemed
like overkill to have multiple DataGridViews just to support my different
column sets.

So, basically, it looks like I'll stick with my current solution of
reloading the columns when I need to switch the column set. I was hoping
that the DataGridView would have duplicated the DataGrid's
DataGridTableStyle functionality somehow, but it certainly looks like this
is not the case.

Thanks again,

- Mitchell S. Honnert
Yeah, that's how it looks. But note, a DataTable can have more than one
DataView. So, clearing the DataGridView and Fill()ing it again from the
other DataView should (i'm guessing) be enough.

Personally, i have Subs set my Column Collections (because other
DataGridViews on other forms may use the same collection), by accepting
a DataGridView as an input parameter. If i was handling your case, i'd
most likely just recall the appropriate function using the same
DataGridView, much like you expressed.

B.

Jul 31 '06 #8

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

Similar topics

2
by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
2
by: Scott | last post by:
Hi all. A few days ago i ask this question and got a good quick response. I tried out what they said and it worked. However I have now come to try the same thing in another program and it...
2
by: Carlos | last post by:
Does DataGridTableStyle work in ASP.net ? any time I'm tring to define a varibale lke DataGridTableStyle MyStyle = new DataGridTableStyle(); it give me "The Type or name sapce...
2
by: kerpal | last post by:
Hi all, 1. Could anyone pls clarify the difference between setting the AlternatingBackColor property in DataGridTableStyle and in DataGrid?? 2. How come BackColor and AlternatingBackColor are...
2
by: Brett Romero | last post by:
I can't find what exactly I'm doing wrong that the following DataGridTableStyle is not working on my table. The result set returns 21 columns. I'm only formatting 5 via the TableStyle. I thought...
4
by: Brett Romero | last post by:
I have the following DataGridTableStyle: DataGridTableStyle gridTableStyle = new DataGridTableStyle(); gridTableStyle.MappingName = "myStyle"; DataGridTextBoxColumn dgsc = new...
2
by: jjsavage | last post by:
Hi all, Borland has a TStringGrid component that puts data into a nice grid for Windows display. What's the .NET 2.0 equivalent? I've found a System.Windows.Forms.DataGrid that seems close. Is...
3
by: nita | last post by:
I'm just starting out, and it's incredibly frustrating when I see sample code and then try to implement it. Case in point. I'm populating a collection then binding it to a datagrid. That works...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.