Visual Studio 2003 .Net / C#
I have a datagrid, which is bound to a dataset at runtime when my page
loads. When the user double clicks a row, I need to find out which row they
have selected so I can pass the key value onto another page, which is showing
me more details for the selected row. So in the double click event of the
datagrid I have this code:
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
This generally seemed to be working. BUT.....when the user sorts the
Datagrid by clicking on one of the column headings things go screwy! They
double click for example on row 3, which on the service is now Job number 8
as they are sorting the grid on another value. But row 3 in my dataset is
not Job 8, it is Job 3!
How can I get round this? Is there a better way of getting the selected row
out of datagrid??
Thanks
Steve 4 15138
You need to compare your row index from the datagrid to the row index on the
datatable's default view rather than the datatable itself
Something like this
DataRow CurrentRow =
dsJobList.Tables[0].DefaultView[dgJobs.CurrentRowIndex].Row
"Steve" wrote: Visual Studio 2003 .Net / C#
I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so I can pass the key value onto another page, which is showing me more details for the selected row. So in the double click event of the datagrid I have this code:
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
This generally seemed to be working. BUT.....when the user sorts the Datagrid by clicking on one of the column headings things go screwy! They double click for example on row 3, which on the service is now Job number 8 as they are sorting the grid on another value. But row 3 in my dataset is not Job 8, it is Job 3!
How can I get round this? Is there a better way of getting the selected row out of datagrid??
Thanks
Steve
That doesnt seem to work, it points to the same record as just doing
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
Do i need to set the default view somehow?
"Ben Reese" wrote: You need to compare your row index from the datagrid to the row index on the datatable's default view rather than the datatable itself
Something like this DataRow CurrentRow = dsJobList.Tables[0].DefaultView[dgJobs.CurrentRowIndex].Row
"Steve" wrote:
Visual Studio 2003 .Net / C#
I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so I can pass the key value onto another page, which is showing me more details for the selected row. So in the double click event of the datagrid I have this code:
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
This generally seemed to be working. BUT.....when the user sorts the Datagrid by clicking on one of the column headings things go screwy! They double click for example on row 3, which on the service is now Job number 8 as they are sorting the grid on another value. But row 3 in my dataset is not Job 8, it is Job 3!
How can I get round this? Is there a better way of getting the selected row out of datagrid??
Thanks
Steve
** SOLVED **
I did this:
CurrencyManager xCM =
(CurrencyManager)dgJobs.BindingContext[dgJobs.DataSource, dgJobs.DataMember];
DataRowView xDRV = (DataRowView)xCM.Current;
DataRow xRow = xDRV.Row;
xRow is then a pointer to the current selected row in my datagrid.
Cheers
"Steve" wrote: That doesnt seem to work, it points to the same record as just doing
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
Do i need to set the default view somehow?
"Ben Reese" wrote:
You need to compare your row index from the datagrid to the row index on the datatable's default view rather than the datatable itself
Something like this DataRow CurrentRow = dsJobList.Tables[0].DefaultView[dgJobs.CurrentRowIndex].Row
"Steve" wrote:
Visual Studio 2003 .Net / C#
I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so I can pass the key value onto another page, which is showing me more details for the selected row. So in the double click event of the datagrid I have this code:
DataRow CurrentRow = dsJobList.Tables[0].Rows[dgJobs.CurrentRowIndex];
This generally seemed to be working. BUT.....when the user sorts the Datagrid by clicking on one of the column headings things go screwy! They double click for example on row 3, which on the service is now Job number 8 as they are sorting the grid on another value. But row 3 in my dataset is not Job 8, it is Job 3!
How can I get round this? Is there a better way of getting the selected row out of datagrid??
Thanks
Steve
Steve,
Assuming that your datagrid is a windowforms datagrid, than the
currencymanager position gives you the position of the current row number in
the datasource.
((CurrencyManager)BindingContext[dataGrid1.DataSource]).Position;
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jawahar Rajan |
last post by:
All,
I have a datagrid that I use in a ASP.net web page that loads customer data
based on the selected customer ID
Some Customers will have no data in the database (which is oracle 9.2) . So
I...
|
by: amber |
last post by:
I have a datagrid, based on a dataview (filled with dataset data from SQL
server).
The dataview contains an ID field, but this field isn't in the datagrid.
How can I get the ID associated with...
|
by: mrstrong |
last post by:
Gday,
Am new to using datagrids so if anyone could assist or point in the right
direction in terms of resources - that would be much appreciated...
I have a form that has:
- a datagrid...
|
by: aaa |
last post by:
Hi
I am trying to create a read-only DataGrid that would always have
current row selected. Currently, I am using method:
public void SelectDataGridRow(DataGrid dg)
{
if (dg.CurrentRowIndex >...
|
by: Christopher Weaver |
last post by:
I want to set a value in a specific field in the current row of a DataSet.
This seems like the most basic thing to do but I can't find the syntax for
identifying the current row.
IOW, I can do...
|
by: Carolyn Vo |
last post by:
I have a datagrid in my web control class that I am trying to get the current
rows displayed for. I have enabled paging on the datagrid so if the user is
currently on page 3 of 8, and if I have...
|
by: Becker |
last post by:
Very simple, I have a datagrid on a windows form. I load some rows in it.
I click a column header and it sorts ascending. I click it again it sorts
descending. This is great, but what I want to...
|
by: Steve |
last post by:
Visual Studio 2003 .Net / C#
I have a datagrid, which is bound to a dataset at runtime when my page
loads. When the user double clicks a row, I need to find out which row they
have selected so...
|
by: neo008 |
last post by:
Hi all,
I'm using Datagrid to show data on forms. All other things are working fine..like add,update, delete and pointer movement.
I have selected HIghlite row property of datagrid and it...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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...
| |