473,721 Members | 2,074 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 26851
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
16305
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
1970
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
4872
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
1349
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
2555
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
1355
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
2207
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
1495
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
8847
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
9372
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...
1
9137
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9071
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...
1
6675
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
5991
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4490
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
3197
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
3
2135
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.