PC Review


Reply
Thread Tools Rate Thread

DataGridView row selection

 
 
Lennart
Guest
Posts: n/a
 
      21st Jul 2006
Hi

I have a DataGridView on a Form filled with data from a DataTable. When I
Load this form I want to select a row in the DataGridView depending on a
selected Primary Key index;

How do I do this?

/Lennart


 
Reply With Quote
 
 
 
 
Dave Sexton
Guest
Posts: n/a
 
      21st Jul 2006
Hi Lennart,

I'm not exactly sure what you are asking, but here is some code that will
select the row of the DataGridView that is bound to a DataRow with a
specific primary key value:

int primaryKey = 5;

// assuming dataGridView1 is bound to dataTable
int rowIndex = dataTable.Rows.IndexOf(dataTable.Rows.Find(primaryKey));

dataGridView1.Rows[rowIndex].Selected = true;

You can replace "dataTable.Rows" with "dataView" in the above code if
dataView is a DataView to which the DataGridView is bound instead of
dataTable.

- Dave Sexton

"Lennart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I have a DataGridView on a Form filled with data from a DataTable. When I
> Load this form I want to select a row in the DataGridView depending on a
> selected Primary Key index;
>
> How do I do this?
>
> /Lennart
>



 
Reply With Quote
 
Lennart
Guest
Posts: n/a
 
      23rd Jul 2006
Hi Dave

You put me on the right track, but the correct way turned out to be this.

dataGridView1.FirstDisplayedScrollingRowIndex =
myTable.Rows.IndexOf(myTable.Rows.Find(myIndex));

dataGridView1.CurrentCell = dataGridView1.FirstDisplayedCell;

/Lennart

"Dave Sexton" <dave@jwa[remove.this]online.com> skrev i meddelandet
news:%(E-Mail Removed)...

> Hi Lennart,
>
> I'm not exactly sure what you are asking, but here is some code that will
> select the row of the DataGridView that is bound to a DataRow with a
> specific primary key value:
>
> int primaryKey = 5;
>
> // assuming dataGridView1 is bound to dataTable
> int rowIndex = dataTable.Rows.IndexOf(dataTable.Rows.Find(primaryKey));
>
> dataGridView1.Rows[rowIndex].Selected = true;
>
> You can replace "dataTable.Rows" with "dataView" in the above code if
> dataView is a DataView to which the DataGridView is bound instead of
> dataTable.
>
> - Dave Sexton
>
> "Lennart" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi
>>
>> I have a DataGridView on a Form filled with data from a DataTable. When
>> I Load this form I want to select a row in the DataGridView depending on
>> a selected Primary Key index;
>>
>> How do I do this?
>>
>> /Lennart
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initializing DataGridView selection Duy Lam Microsoft C# .NET 0 30th Aug 2010 09:30 PM
on datagridview row selection... A Microsoft Dot NET Framework Forms 0 20th Oct 2006 11:26 AM
DataGridView Selection Paul Cheetham Microsoft C# .NET 0 22nd May 2006 07:31 PM
DataGridView and selection Andy Microsoft Dot NET Framework Forms 0 22nd Mar 2006 09:18 PM
Clearing selection in DataGridView when user clicks outside the DataGridView control djyakov@gmail.com Microsoft Dot NET Framework Forms 0 16th Feb 2006 06:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:49 AM.