473,839 Members | 1,423 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 26894
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
16309
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
1978
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
4877
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
1359
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
4555
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
2565
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
1363
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
2215
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
1503
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
9855
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
10908
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
10586
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
9426
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...
0
7017
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
5682
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...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
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
3134
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.