473,509 Members | 2,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resort dataset table after add new row

I have a table in a dataset whose fields are bound to various controls on my
form. The records are sorted by primary key so when I use the
currencymanager to navigate the data, it all appears sorted. When I add a
new row to this table and save it (using dataadapter.update) it appears at
the end of the list no matter where it should fall in the sorted list. When
I exit and re-enter the form the newly added record is then presented in the
proper sorted order. Clearly when re-entering the form I reload the
dataset, create all the data bindings, etc all from scratch. My question
is that, short of reloading the entire dataset and recreating the bindings,
what do I need to do to "reorder" the data once I add the new row so that
the new row will appear in the proper place in the list. I've tried a
CurrencyManager.Refresh and sorting the dataset.table by the proper column,
but in each case the Currencymanager seems to get confused and all types of
weirdness happens.
Any suggestions? Thanks...
Dec 12 '05 #1
2 7627
John,
I have a table in a dataset whose fields are bound to various controls on
my form. The records are sorted by primary key so when I use the
currencymanager to navigate the data, it all appears sorted. When I add a
new row to this table and save it (using dataadapter.update) it appears at
the end of the list no matter where it should fall in the sorted list.
Gladly enough otherwise I would never be able to do this
ds.tables(x).rows(count-1) = the last added record
When I exit and re-enter the form the newly added record is then presented
in the proper sorted order. Clearly when re-entering the form I reload
the dataset, create all the data bindings, etc all from scratch. My
question is that, short of reloading the entire dataset and recreating the
bindings, what do I need to do to "reorder" the data once I add the new
row so that the new row will appear in the proper place in the list. I've
tried a CurrencyManager.Refresh and sorting the dataset.table by the
proper column, but in each case the Currencymanager seems to get confused
and all types of weirdness happens.
Any suggestions? Thanks...


Use the dataview or better just the defaultview which is the same inbuild in
every datatable

ds.tables(0).defaultview.sort = "Mycolumn" is enough
whatever.datasource = ds.tables(0).defaultview

I hope this helps,

Cor
Dec 12 '05 #2
Hi Cor,

Thanks for the tip. I got it to work (finally!), but let me give you the
full story of what I had to do...
1. had to make all references to the databinding equal to the
ds.tables("myfilename").defaultview (previously I just used
ds.tables("myfilename") )
2. using the defaultview.sort put my added record in order, BUT it affected
the positioning of my databinding the next time I added a record. That is,
the first time I added a record (when the sort was not in effect) I added
the new row and positioned to the last record (ie: count-1). During the
processing of the added record I did the defaultview.sort so the added
record was in it's proper order, HOWEVER the next time I added a record
(the key field is blank when adding a new record) the position of the record
was 0 and NOT count-1 (because of the sort). So, I simply moved the
defaultview.sort statement to the form.load sub and now I always position to
row 0 when entering the data for a newly added record, and everything works
fine.
Thanks again for the help.
John

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oa****************@tk2msftngp13.phx.gbl...
John,
I have a table in a dataset whose fields are bound to various controls on
my form. The records are sorted by primary key so when I use the
currencymanager to navigate the data, it all appears sorted. When I add
a new row to this table and save it (using dataadapter.update) it appears
at the end of the list no matter where it should fall in the sorted list.


Gladly enough otherwise I would never be able to do this
ds.tables(x).rows(count-1) = the last added record
When I exit and re-enter the form the newly added record is then
presented in the proper sorted order. Clearly when re-entering the form
I reload the dataset, create all the data bindings, etc all from scratch.
My question is that, short of reloading the entire dataset and recreating
the bindings, what do I need to do to "reorder" the data once I add the
new row so that the new row will appear in the proper place in the list.
I've tried a CurrencyManager.Refresh and sorting the dataset.table by the
proper column, but in each case the Currencymanager seems to get confused
and all types of weirdness happens.
Any suggestions? Thanks...


Use the dataview or better just the defaultview which is the same inbuild
in every datatable

ds.tables(0).defaultview.sort = "Mycolumn" is enough
whatever.datasource = ds.tables(0).defaultview

I hope this helps,

Cor

Dec 12 '05 #3

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

Similar topics

1
1077
by: Justin | last post by:
Is there an easy way to export a dataset table as a text file such as a .net class. If not do you have any suggestions? Thanks, Justin.
1
1839
by: James Jensen | last post by:
I ran into a snippet of code that uses a FOR EACH loop to step through the rows in a Dataset.Table object. I understand that the FOR EACH statement implements the MoveNext function of the...
1
251
by: jaawaad | last post by:
Does anyone know how i can compute values from dataset table before assigning datagrid source to it??? My data table looks something like this. DATE CAT STEP ...
2
2717
by: forforumsid | last post by:
Hi all I have a Dataset name: dsMain I popullate with all the data from the database on form load event I have a requirement to filter data as per users requirement on a button click event ...
0
1290
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0. I have used 2 DirectorySearchers to retrieve Active Directory data and put them into 2 separate dataset tables. I want to create a 3rd dataset table by using the...
2
1746
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0 I used 2 DirectorySearchers to retrieve data from Active Directory and placed them in 2 dataset tables. I need to perform the SQL equuvakebt of join operation to...
3
1861
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Are there any good built-in or availble functions that I can call to sort my dataset datatalbe based on 1 or more of the table's columns? -- Thanks.
9
1632
by: =?Utf-8?B?Sm9obiBSZWV2ZQ==?= | last post by:
How to put a list of rows from dataset table into an array ? I tried with this code but it doesn't help. ArrayList arrayList = new ArrayList(); foreach (DataRow dr in...
0
1162
by: Nick L | last post by:
Here is the PowerShell script I've been working on (.NET question is at the bottom): ### setup SQL connection $conn = new-object System.Data.SqlClient.SqlConnection $conn.ConnectionString =...
0
7136
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
7344
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,...
1
7069
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
5652
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,...
0
4730
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
3216
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
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
441
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...

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.