.NETGURU
Cannot get the changes dataset correctly!
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

miyakejess (VIP)
Hi All,

I have a problem to get the changes of the dataset in the datagrid after
sorting the datagrid.
Firstly, I change some rows in the datagrid, and sort it. Then Update it.

And i trace my program, i found that, the dataview can get the correct data,
but not the dataset.getchanges() functions

The codes are~
Dim dvMRM = dsABC.ABC.DefaultView
Dim dsMRM = dvMRM.Table.Dataset

' I try to get the dvMRM's dataset by getxml() to see, and i found that they
get the correct dataset which the value has been changed after my editing

'but when i try to get the the changes
Me.dsMRM.getChanges(DataRowState.Modified)

I found that it cannot get all the changes of the dataset!
If i edit N rows, it will only change N-1 Rows

Reply to this message...
 
    
Procrustes (VIP)
Problem is in sorting. When you change n rows in grid an click on column
header for sort action, nth row will not be changed. You must set focus to
other row or some button or anything that can be focused, only then will be
executed EndEdit method for nth row, and changed Row will get status
modified(in DataSet) and will be saved.
If you set AlowSort = false, you will not get that problem.

Best wishes,
P.

"miyakejess" wrote:

[Original message clipped]

Reply to this message...
 
    
miyakejess (VIP)
OIC~~Thanks~
But, How can I send focused on a row?
Also, another question is how can I identify the action "Sorting" on the
Datagrid after I click on the Header of datagrid?
Reply to this message...
 
    
Prokrust
I find this for you(text between " **** start *** and **** end ***").
It will answer both of your question:
1. "But, How can I send focused on a row?"
Right after sort, focus will be back to current row.
2. "Also, another question is how can I identify the action "Sorting" on the
Data after I click on the Header of datagrid?"
Mouse down event in code below, contains answer to your question. It shows
how to detect click on column header. Any click to column header with
property AllowSorting = true, is "sort action".

Best wishes,
P.

**** start ***
Re-Selecting The Currently Selected Row After A DataGrid Sort

This is a follow-up to this previous post about sorting a DataGrid. It turns
out that the person who originally asked the question about knowing when the
sort would occur, wanted to know this for the purpose of re-selecting the
currently selected row after the sort. Well, as it turns out this is
entirely possible, but it requires some deeper digging into the data-binding
aspects of WinForms (which I love btw). ;)
So here's what you'll need to do. First things first, you're going to need
to watch for the sort to happen as was detailed in the previous post. Upon
detecting the sort about to happen you must record a key value for the
currently selected row in a state field (probably in your Form). Now, here's
where the deeper knowledge of data-binding comes into play. You must also
attach an event listener to the ItemChanged event of the CurrencyManager for
the DataTable/DataView you've bound your DataGrid to. The ItemChanged event
will fire after the sort takes place at which point you use the DataView's
(DataTable::DefaultView if you're bound directly to a DataTable) Find method
to locate the row in the view by the key value that you stored in your state
field in the sort detection event logic. Once you've found the new position
of the row in the DataView after the sort, you set the CurrencyManager's
Position property to that index.
Ok, this might sound complex, but lemme show you just how easy it is with
some code. For the purposes of keeping this code concise, assume this code
is in a Form subclass which contains a DataGrid in a member variable called
"myDataGrid". This DataGrid is then bound to a DataTable, stored in a member
variable called "myDataTable" which has a key column named "key" of type
int:

public class MyForm : Form
{
private int currentlySelectedRowId = -1;

public MyForm()
{
this.InitializeComponent();

// Get the CurrencyManager for the bound DataTable
CurrencyManager dataTableCurrencyManager =
(CurrencyManager)this.myDataGrid.BindingContext[this.myDataTable];

// Hook up to the ItemChanged event
dataTableCurrencyManager.ItemChanged += new
ItemChangeEventHandler(this.myDataTableCurrencyManager_ItemChanged);
}

private void myDataGrid_MouseUp(object sender, MouseEventArgs args)
{
DataGrid.HitTestInfo hitTestInfo = this.myDataGrid.HitTest(args.X,
args.Y);

if(hitTestInfo.Type == DataGrid.HitTestType.ColumnHeader)
{
// Get the CurrencyManager for the bound DataTable
CurrencyManager dataTableCurrencyManager =
(CurrencyManager)this.myDataGrid.BindingContext[this.myDataTable];

// Get the current DataRowView
DataRowView currentRowView =
(DataRowView)dataTableCurrencyManager.Current;
// Remember the currently selected row ID
this.currentlySelectedRowId = (int)currentRowView["key"];
}
}

private void myDataTableCurrencyManager_ItemChanged(object sender,
ItemChangeEventArgs args)
{
// Only execute this logic if we're in the state of sorting
if(this.currentlySelectedRowId != -1)
{
// Find the new position of the row now that it's been sorted
int newPosition =
this.myDataTable.DefaultView.Find(this.currentSelectedRowId);

// Get the CurrencyManager for the bound DataTable
CurrencyManager dataTableCurrencyManager =
(CurrencyManager)this.myDataGrid.BindingContext[this.myDataTable];

// Change the position of the currency manager
dataTableCurrencyManager.Position = newPosition;

// Reset sorting state
this.currentSelectedRowId = -1;
}
}
}

**** end ***

(source:
http://216.239.59.104/search?q=cache:DL_Iq_gsRR8J:weblogs.asp.net/dmarsh/archive/2003/01/22/646.aspx+datagrid+after+sort&hl=sl)

"miyakejess" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
miyakejess (VIP)
Actually, I don' t know how to code the following function in VB.net
As i cannot find this event handler in the drop down list box in the visual
studio .net

private void myDataTableCurrencyManager_ItemChanged(object sender,
ItemChangeEventArgs args)
{
// Only execute this logic if we're in the state of sorting
if(this.currentlySelectedRowId != -1)
{
// Find the new position of the row now that it's been sorted
int newPosition =
this.myDataTable.DefaultView.Find(this.currentSelectedRowId);

// Get the CurrencyManager for the bound DataTable
CurrencyManager dataTableCurrencyManager =
(CurrencyManager)this.myDataGrid.BindingContext[this.myDataTable];

// Change the position of the currency manager
dataTableCurrencyManager.Position = newPosition;

// Reset sorting state
this.currentSelectedRowId = -1;
}
}
}

Reply to this message...
 
 
System.Data.DataRowState
System.Data.DataRowView
System.Data.DataSet
System.Data.DataTable
System.Data.DataView
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.CurrencyManager
System.Windows.Forms.DataGrid
System.Windows.Forms.MouseEventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification