473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to programmaticall y select a row in a datagrid

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

dataGridView2.C learSelection() ;
dataGridView2.R ows[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.C urrentRow;
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 26859
Dave,
dataGridView.Cu rrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discuss ions.microsoft. comwrote:
I cannot programmaticall y select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.C learSelection() ;
dataGridView2.R ows[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.C urrentRow;
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.Cu rrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discuss ions.microsoft. comwrote:
I cannot programmaticall y select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.C learSelection() ;
dataGridView2.R ows[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.C urrentRow;
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...@discuss ions.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.Cu rrentCell = dataGridView[<column>, <row>]
will do the trick.
Hope this helps,
jake
On Jun 7, 1:14 pm, Parrot <Par...@discuss ions.microsoft. comwrote:
I cannot programmaticall y select a row in datagridview control. I use the
following instruction to change the selection of a row
dataGridView2.C learSelection() ;
dataGridView2.R ows[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.C urrentRow;
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 (DataGridViewRo w row in this.dataGridVi ew.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.Cel ls[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 programmaticall y select a row in datagridview control. I use the
following instruction to change the selection of a row

dataGridView2.C learSelection() ;
dataGridView2.R ows[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.C urrentRow;
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16306
by: Dave Wijay | last post by:
Hi Does anybody know how to programmatically select items (rows) of a ListView in C#.NET Thanks in advanc Dave
4
1971
by: J1C | last post by:
If I only know the value of an option is a select list, is it possible to programmatically select that option? I would be returning the value from a server-side script ...
1
4874
by: developer | last post by:
I have a Windows form that contains a datagrid populated with a table in my database. When i load my form i want a particular row in my datagrid to be selected. How can i do that Thanks
0
1351
by: cmc | last post by:
Hi, I have a web application that programmatically creates DataGrids. When I create the DataGrid I set the EditItemStyle.CssClass = "DataGridStyleEdit" - the background of the row and the column see the style applied, however my text boxes to not reflect any of my style. Is there a way to fix this? I have tried to change my CSS to use INPUT.EditGridStyle, but that did not seem to change the Text boxes. (the style seems to be applied...
2
4552
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingwebservercontroltemplatesprogrammatically.asp I have narrowed down the problem comes in when the _DataBinding handler is called and the literal text is being assigned, but I can't figure out beyond that. The main problem is that...
1
2557
by: Jay | last post by:
I'm wondering if anyone has even encountered a control or other scripting that will automatically rotate the rows of a datagrid... I am in the process of building an asp.net application that will display statistics on a large LCD display for viewing by people within the room (30 feet away). One problem is that the screen can obviously only display so much legible data at a time. I may have upwards of 60 or 70 rows to display on a rotating...
2
1356
by: John | last post by:
Hi all, I searched everywhere today but to no avail - I need to programmatically remove rows (DataGridItems) from a datagrid. Unfortunately,I can't have a delete button/control of any kind but must do it in the ItemDataBound event. Surely there must be a way to do this. Any help regarding this would already be more than Google could offer.
2
2209
by: jaYPee | last post by:
Anyone know how to add record to a datagrid programmatically? Say for example I have two textboxes in my form and a datagrid. When I click a button the value of two textboxes will be added as a new row to my datagrid. Thanks in advance.
0
1496
by: TB | last post by:
Hi All For reasons unknown to me, the Page.IsPostBack is always false when I click a link in a hyperlink column of a datagrid which is created programmatically. My code in a page called list.aspx: sub creategrid()
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.