473,765 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid / Dataview won't sort

I am having trouble sorting a datagrid. I have read numerous posts on
this and other lists, and tried most of the suggestions, but none of
them have worked for me yet. I populate a dataset from two queries,
then I want to sort the data and bind it to a datagrid. Regardless of
what I have tried, the datagrid is populated with the unsorted data.
Any assistance you have would be appreciated.

I have attempted the sort using the dataview.sort method. See Below:

DataView view = this.dsInventor y1.Tables["vInvLocDet ail"].DefaultView;
view.Sort = "invTypeDes c ASC";
this.DataGrid1. DataSource = view;
this.DataGrid1. DataBind();
I have also attempted creating the dataview, specifying the sort for
the dataview, then parsing the results of the dataview into another
datatable and binding the datagrid to that datatable. See below:

DataView dv = new DataView(this.d sInventory1.vIn vLocDetail, "",
"invTypeDes c", DataViewRowStat e.CurrentRows);
dv.Sort = "invTypeDes c";
DataTable dt = new DataTable();
foreach (DataRow row in dv.Table.Rows)
{
dt.ImportRow(ro w);
}
this.DataGrid1. DataSource = dt;
this.DataGrid1. DataBind();

Thank you for helping!

Nov 19 '05 #1
1 1772
Troy try looking at this at:-
http://www.dotnetjohn.com/articles.aspx?articleid=108
Hope that helps
Patrick

<tr*********@gm ail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I am having trouble sorting a datagrid. I have read numerous posts on
this and other lists, and tried most of the suggestions, but none of
them have worked for me yet. I populate a dataset from two queries,
then I want to sort the data and bind it to a datagrid. Regardless of
what I have tried, the datagrid is populated with the unsorted data.
Any assistance you have would be appreciated.

I have attempted the sort using the dataview.sort method. See Below:

DataView view = this.dsInventor y1.Tables["vInvLocDet ail"].DefaultView;
view.Sort = "invTypeDes c ASC";
this.DataGrid1. DataSource = view;
this.DataGrid1. DataBind();
I have also attempted creating the dataview, specifying the sort for
the dataview, then parsing the results of the dataview into another
datatable and binding the datagrid to that datatable. See below:

DataView dv = new DataView(this.d sInventory1.vIn vLocDetail, "",
"invTypeDes c", DataViewRowStat e.CurrentRows);
dv.Sort = "invTypeDes c";
DataTable dt = new DataTable();
foreach (DataRow row in dv.Table.Rows)
{
dt.ImportRow(ro w);
}
this.DataGrid1. DataSource = dt;
this.DataGrid1. DataBind();

Thank you for helping!

Nov 19 '05 #2

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

Similar topics

4
2843
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the form/grid first opens up and the grid is immediately sorted the TB don't reflect the sorted data of the First row of the grid. Note: Initially the black grid indicator arrow points to the first row. If the user choses another row and then sorts...
7
2467
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here
1
2352
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current page. i.e. If I have: IntegerValue StringValue CurrencyValue 0 Item 0 0 1 Item 1 1.23
2
1610
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview. The following control simply responds to a sort request and/or a pageing reqeust with an empty table (header only). Any ideas ? Code behind : namespace OakTree.data {
5
2791
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go to the database to get the next page. Is there a way to use the dataset to allow us to read back and forth in it instead of going back to the database to get it? Thanks,
1
2159
by: P Dietz | last post by:
Hello, I'm using a datagrid to show data (ok, what else...), and by doubleclick on a row I first hide the Datagrid-Form and start another form to work with the data. After returníng to the Datagrid-Form and reload the data I would like to jump to the same row as i was before. To get the actual row before leave the form, I use aktID = dvProt(Me.dgProt.CurrentRowIndex)!naqs_ID.toString
8
1828
by: Dennis | last post by:
How do I sort a DataGrid Column in code without clicking on the column header? -- Dennis in Houston
9
3378
by: John Hernry | last post by:
I have been watching the dotnet newsgroups for a couple of weeks now and scouring the net looking for a solution to my datagrid find functionality. With no luck. I am hoping that you can help me. I am an old VB6 coder used to using Sheridan controls, and I am just starting to learn the .net world. I am upgrading my music catalogue database, where the data is stored in an Access mdb file.
4
1544
by: G .Net | last post by:
Hi I have a question which I hope you can help with. I am setting the DataSource of a DataGrid to be a DataView. I am sorting the DataView by various fields which include a Date. When I create a new row in the DataGrid and set the date to me within the current sort range, the newly created row "jumps" to its correct position in the grid. This obviously makes sense because it is following the sort rule.
0
9568
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
9399
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
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
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
9835
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
8832
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...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.