Sort order datagrid and datasets

F

Filip De Backer

Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip
 
N

Nick Carter

Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView[dataGrid.CurrentRowIndex].Row;

Nick Carter
 
O

One Handed Man

OK, maybe that returns the row. But it doesent give him the index unless I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView[dataGrid.CurrentRowIndex].Row;

Nick Carter


Filip De Backer said:
Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip
 
N

Nick Carter

That's true but it isn't clear whether he wants the index or the row. I
guess we'll find out soon.

Nick

One Handed Man said:
OK, maybe that returns the row. But it doesent give him the index unless I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView[dataGrid.CurrentRowIndex].Row;

Nick Carter


Filip De Backer said:
Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip
 
O

One Handed Man

Interestingly enough, do you know how to find the index given the row ?

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
That's true but it isn't clear whether he wants the index or the row. I
guess we'll find out soon.

Nick

One Handed Man said:
OK, maybe that returns the row. But it doesent give him the index unless I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView[dataGrid.CurrentRowIndex].Row;

Nick Carter


Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip
 
N

Nick Carter

Mmm. I guess that I would use the DataView.Find() or DataView.FindRows()
methods to get the row index in the DataView and this index is the same as
the DataGrid's index. Do you know of a better way ?

Nick

One Handed Man said:
Interestingly enough, do you know how to find the index given the row ?

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
That's true but it isn't clear whether he wants the index or the row. I
guess we'll find out soon.

Nick

message news:[email protected]...
OK, maybe that returns the row. But it doesent give him the index
unless
I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView[dataGrid.CurrentRowIndex].Row;

Nick Carter


Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip
 
N

Nick Carter

Filip,

Sorry, I wasn't being clear. The DataGrid uses a DataView internally when
the source is a DataTable so even though you don't have your own DataView
the DataGrid does have one and you can get at it using the code I provided
in a previous posting.

Nick

Filip De Backer said:
I don't use a DataView because I bind my datagrid directly
to the dataset. But I have searched for some documentation
on DataViews and it seems that there is always a default
dataview with the DataTables of a dataset.

But my program is now working with the CurrencyManager
like you told me.

Filip
-----Original Message-----
Mmm. I guess that I would use the DataView.Find() or DataView.FindRows()
methods to get the row index in the DataView and this index is the same as
the DataGrid's index. Do you know of a better way ?

Nick

"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote in
(e-mail address removed)> wrote
in
message OK, maybe that returns the row. But it doesent give
him the index
unless
I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext [dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView [dataGrid.CurrentRowIndex].Row;

Nick Carter


Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip


.
 
O

One Handed Man

When doesent it use an internal dv representation ?, presumably if the
source is a dataview

Regards

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
Filip,

Sorry, I wasn't being clear. The DataGrid uses a DataView internally when
the source is a DataTable so even though you don't have your own DataView
the DataGrid does have one and you can get at it using the code I provided
in a previous posting.

Nick

Filip De Backer said:
I don't use a DataView because I bind my datagrid directly
to the dataset. But I have searched for some documentation
on DataViews and it seems that there is always a default
dataview with the DataTables of a dataset.

But my program is now working with the CurrencyManager
like you told me.

Filip
-----Original Message-----
Mmm. I guess that I would use the DataView.Find() or DataView.FindRows()
methods to get the row index in the DataView and this index is the same as
the DataGrid's index. Do you know of a better way ?

Nick

"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote in
message Interestingly enough, do you know how to find the index given the row ?

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
That's true but it isn't clear whether he wants the index or the row. I
guess we'll find out soon.

Nick

"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote
in
message OK, maybe that returns the row. But it doesent give him the index
unless
I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager = (CurrencyManager)
dataGrid.TopLevelControl.BindingContext
[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView) currencyManager.List;
DataRow dataRow = (DataRow) dataView [dataGrid.CurrentRowIndex].Row;

Nick Carter


Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by clicking on a
certain column, is the sort order of the dataset also
change.
Because when you click on a cell in the datagrid you can
have the index with myDataGrid.CurrentRowIndex. Is this
index of the selected row in the datagrid the same index
as the index of the corresponding record in the table of
the dataset?

thanks,

Filip










.
 
N

Nick Carter

Mmm. I'm not sure. I thought that it didn't use a DataView if the source was
an array or "non-databased" collections of some kind. But I wouldn't swear
to it.

Nick

One Handed Man said:
When doesent it use an internal dv representation ?, presumably if the
source is a dataview

Regards

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
Nick Carter said:
Filip,

Sorry, I wasn't being clear. The DataGrid uses a DataView internally when
the source is a DataTable so even though you don't have your own DataView
the DataGrid does have one and you can get at it using the code I provided
in a previous posting.

Nick

Filip De Backer said:
I don't use a DataView because I bind my datagrid directly
to the dataset. But I have searched for some documentation
on DataViews and it seems that there is always a default
dataview with the DataTables of a dataset.

But my program is now working with the CurrencyManager
like you told me.

Filip

-----Original Message-----
Mmm. I guess that I would use the DataView.Find() or
DataView.FindRows()
methods to get the row index in the DataView and this
index is the same as
the DataGrid's index. Do you know of a better way ?

Nick

"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote in
message Interestingly enough, do you know how to find the index
given the row ?

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
That's true but it isn't clear whether he wants the
index or the row. I
guess we'll find out soon.

Nick

"One Handed Man" <terry_burnsREMOVE%FOR%NO%
(e-mail address removed)> wrote
in
message OK, maybe that returns the row. But it doesent give
him the index
unless
I'm
mistaken ?



--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
message
Filip,

No, they are not the same.

You can get the correct DataRow like this:-

CurrencyManager currencyManager =
(CurrencyManager)
dataGrid.TopLevelControl.BindingContext
[dataGrid.DataSource,
dataGrid.DataMember];
DataView dataView = (DataView)
currencyManager.List;
DataRow dataRow = (DataRow) dataView
[dataGrid.CurrentRowIndex].Row;

Nick Carter


in message
Hi,

I've bound a dataset to a datagrid.
The datagrid has 4 columns.
When I change the sort order of the data by
clicking on a
certain column, is the sort order of the
dataset also
change.
Because when you click on a cell in the
datagrid you can
have the index with myDataGrid.CurrentRowIndex.
Is this
index of the selected row in the datagrid the
same index
as the index of the corresponding record in the
table of
the dataset?

thanks,

Filip










.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top