473,756 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I sort the columns (not rows) in a DataGrid?

I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to
know.

Jon
Nov 15 '05 #1
11 1350
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all Columns
DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat
feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd like to know.

Jon

Nov 15 '05 #2
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all Columns DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd

like to
know.

Jon


Nov 15 '05 #3
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all Columns DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a Windows Forms app in which I have a DataGrid control. I have a
custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which is
managed by the collection)? Is there a simple process to do this, while
still using my simple class and not resorting to ADO.NET or XML? I would
prefer not to move to ADO.NET or XML, but if it's my only option I'd

like to
know.

Jon


Nov 15 '05 #4
Unfortunately, there is no DataGridTableSt yle property in the Windows Forms
DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.Tabl eStyles[0].GridColumnStyl es.AddRange(new
DataGridColumnS tyle[] {.... I don't know what to put here, and
DataGridColumnS tyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all

Columns
DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a Windows Forms app in which I have a DataGrid control. I have a custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which
is
managed by the collection)? Is there a simple process to do this,

while still using my simple class and not resorting to ADO.NET or XML? I would prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
know.

Jon



Nov 15 '05 #5
Unfortunately, there is no DataGridTableSt yle property in the Windows Forms
DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.Tabl eStyles[0].GridColumnStyl es.AddRange(new
DataGridColumnS tyle[] {.... I don't know what to put here, and
DataGridColumnS tyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all

Columns
DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also
their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a Windows Forms app in which I have a DataGrid control. I have a custom class that has several properties exposed, and I have made this
class, or a collection thereof, the DataSource of the DataGrid. This neat feature of the DataGrid allows the properties to be displayed in a
Collection of this class.

Now, how do I order the columns (not to be confused with the rows, which
is
managed by the collection)? Is there a simple process to do this,

while still using my simple class and not resorting to ADO.NET or XML? I would prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
know.

Jon



Nov 15 '05 #6
In fact, TableStyles[0] fails because there are none.

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:u5******** ******@TK2MSFTN GP09.phx.gbl...
Unfortunately, there is no DataGridTableSt yle property in the Windows Forms DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.Tabl eStyles[0].GridColumnStyl es.AddRange(new
DataGridColumnS tyle[] {.... I don't know what to put here, and
DataGridColumnS tyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all Columns
DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> I have a Windows Forms app in which I have a DataGrid control. I have a
> custom class that has several properties exposed, and I have made
this > class, or a collection thereof, the DataSource of the DataGrid. This

neat
> feature of the DataGrid allows the properties to be displayed in a
> Collection of this class.
>
> Now, how do I order the columns (not to be confused with the rows,

which is
> managed by the collection)? Is there a simple process to do this, while > still using my simple class and not resorting to ADO.NET or XML? I would > prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
> know.
>
> Jon
>
>



Nov 15 '05 #7
In fact, TableStyles[0] fails because there are none.

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:u5******** ******@TK2MSFTN GP09.phx.gbl...
Unfortunately, there is no DataGridTableSt yle property in the Windows Forms DataGrid. There is a TableStyles property, but it is a collection. If I go
MyDataGrid.Tabl eStyles[0].GridColumnStyl es.AddRange(new
DataGridColumnS tyle[] {.... I don't know what to put here, and
DataGridColumnS tyle's constructor is not accessible.

Jon

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thanks!

"Zürcher See" <aq****@cannabi smail.com> wrote in message
news:ud******** ******@TK2MSFTN GP11.phx.gbl...
I think you have to set your own DataGridTableSt yle:

DataGrid.DataGr idTableStyle.Gr idColumnStyles. Clear(); //Remove all Columns
DataGrid.DataGr idTableStyle.Gr idColumnStyles. AddRange(new
DataGrisColumnS tyle[]{ .... }); // Set the columns to display and also their order

And add the columns in the order that you want

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .net> schrieb im Newsbeitrag
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> I have a Windows Forms app in which I have a DataGrid control. I have a
> custom class that has several properties exposed, and I have made
this > class, or a collection thereof, the DataSource of the DataGrid. This

neat
> feature of the DataGrid allows the properties to be displayed in a
> Collection of this class.
>
> Now, how do I order the columns (not to be confused with the rows,

which is
> managed by the collection)? Is there a simple process to do this, while > still using my simple class and not resorting to ADO.NET or XML? I would > prefer not to move to ADO.NET or XML, but if it's my only option I'd

like
to
> know.
>
> Jon
>
>



Nov 15 '05 #8
Found the answer here.

http://support.microsoft.com/default...;EN-US;Q317383

Jon
Nov 15 '05 #9
Found the answer here.

http://support.microsoft.com/default...;EN-US;Q317383

Jon
Nov 15 '05 #10

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

Similar topics

4
2446
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected represents the indes of the actual DataGrid and not the DataView. For example.. Lets say I have 4 rows of data.. In the 4 rows I have an Appt Num of 1,2,3,4... Each representing a data row... I sort DESC so the rows display 4,3,2,1... If I...
3
2547
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
4
9636
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as '07-Mar-05' the expression {..:dd-MMM-yy} works OK Second question, does anyone know hwo to return a date from SQL server in the format '07-Mar-05', as this would be a workaround. At the moment I'm using CONVERT(varchar(12),columnname,6 ) to...
1
2692
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I am missing something basic here... Need help... Thanks much
4
1513
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using VB.NET) that handles the SortCommand event of the data grid. I've included the declaration of the Sub below. EnableViewState is set to false; we reload the DataSource each time the page posts. Would anyone know why this DataGrid doesn't sort? ...
4
2725
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all my rows back to their defaults. I populate the datagrid, resize it accordingly and it works fine...just when I click the headers is when it messes up. It would be fine if I could run my autosizing again after the sorting is done since there...
0
619
by: thomasp | last post by:
I have a datagridview that allows the user to sort the column by clicking on the header of the column the user wishes to sort. I did not code this, it had the ability when the datagrid was populated. My question is how can I chande the cursor to an hourglass when the user clicks the header and change it back to the default once the sort is accomplished. The database is large and the sort takes a few seconds. Need something to show the...
2
2795
by: Scott | last post by:
I am trying to sort a datagrid which contains 5 checkbox columns. All other columns sort properly except these 5 checkbox columns which dont sort at all. I am using ASP.NET 1.1 and this code is located in a user control. The code snippet for binding the checkbox control is as follows and is found in the ItemDataBound event for the datagrid. It appears that the index value never changes...it always seems to reference the orginal...
1
3781
by: Aeric | last post by:
I have read the following topic: sorting dataset and I am facing the same issue. I am designing a report. I have fill a dataset with the results from a query. From the results, I used to set the value from the items into an array and display on the aspx page in a table form. The reason why I don't use Datagrid or Gridview is because the table has to be design where the column headers has 2 or more rows and some columns need to be merged...
0
9303
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9117
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9679
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9541
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8542
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.