469,366 Members | 2,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

How to programmatically select a row in a datagrid

I cannot programmatically select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.ClearSelection();
dataGridView2.Rows[currentrow].Selected = true;

When I add another entry to the datagrid, I return to this routine and check
for the current row as follows:

DataGridViewRow row = dataGridView2.CurrentRow;
currentrow = row.Index;

However, unless I manually check the row with my mouse, the currentrow
always returns a 0 even though the 2nd row is highlighted. How can I make
the program retain the select status that I set up in the first routine? Or
how do I determine the current row value?
Dave
Jun 27 '08 #1
4 25571
Dave,
dataGridView.CurrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discussions.microsoft.comwrote:
I cannot programmatically select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.ClearSelection();
dataGridView2.Rows[currentrow].Selected = true;

When I add another entry to the datagrid, I return to this routine and check
for the current row as follows:

DataGridViewRow row = dataGridView2.CurrentRow;
currentrow = row.Index;

However, unless I manually check the row with my mouse, the currentrow
always returns a 0 even though the 2nd row is highlighted. How can I make
the program retain the select status that I set up in the first routine? Or
how do I determine the current row value?
Dave
Jun 27 '08 #2
Jake;
Thanks so much for your help. Your suggestion worked. What would we do
without these forums? Thanks again.
Dave

"jake" wrote:
Dave,
dataGridView.CurrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discussions.microsoft.comwrote:
I cannot programmatically select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.ClearSelection();
dataGridView2.Rows[currentrow].Selected = true;

When I add another entry to the datagrid, I return to this routine and check
for the current row as follows:

DataGridViewRow row = dataGridView2.CurrentRow;
currentrow = row.Index;

However, unless I manually check the row with my mouse, the currentrow
always returns a 0 even though the 2nd row is highlighted. How can I make
the program retain the select status that I set up in the first routine? Or
how do I determine the current row value?
Dave
Jun 27 '08 #3
You're welcome.
"What would we do without these forums?" We would spend a lot of
money on gas and phone bills and still get nowhere!
But seriously, glad I can help.
jake
On Jun 8, 12:16 am, Parrot <Par...@discussions.microsoft.comwrote:
Jake;
Thanks so much for your help. Your suggestion worked. What would we do
without these forums? Thanks again.
Dave

"jake" wrote:
Dave,
dataGridView.CurrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discussions.microsoft.comwrote:
I cannot programmatically select a row in datagridview control. I use the
following instruction to change the selection of a row
dataGridView2.ClearSelection();
dataGridView2.Rows[currentrow].Selected = true;
When I add another entry to the datagrid, I return to this routine and check
for the current row as follows:
DataGridViewRow row = dataGridView2.CurrentRow;
currentrow = row.Index;
However, unless I manually check the row with my mouse, the currentrow
always returns a 0 even though the 2nd row is highlighted. How can I make
the program retain the select status that I set up in the first routine? Or
how do I determine the current row value?
Dave
Jun 27 '08 #4
foreach (DataGridViewRow row in this.dataGridView.Rows)
{
// TODO Why can a cell be null, then wrapMode is set to
false, then I select 2. time?
if (row.Cells[0].Value == null)
row.Cells[0].Value = false;

// compare Select checkbox and RMS database value and
RMS DataGridView column
if (((bool)row.Cells[currencolunm].Value) == true && ---
other condsion )
{
--

In Short Cast Select cell to bool + the row condision as you see 2. time you
select the select state can be null and not only true/false why I still not
know.
Kim S.
"Parrot" wrote:
I cannot programmatically select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.ClearSelection();
dataGridView2.Rows[currentrow].Selected = true;

When I add another entry to the datagrid, I return to this routine and check
for the current row as follows:

DataGridViewRow row = dataGridView2.CurrentRow;
currentrow = row.Index;

However, unless I manually check the row with my mouse, the currentrow
always returns a 0 even though the 2nd row is highlighted. How can I make
the program retain the select status that I set up in the first routine? Or
how do I determine the current row value?
Dave
Jul 14 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by J1C | last post: by
1 post views Thread by developer | last post: by
1 post views Thread by Jay | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.