473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Selecting rows on a datagrid via code

I have a form with two text boxes, a button, and a datagrid control
which is bound to my SQL DB. There are two columns on the datagrid,
one for each of the textboxes on the form. I have already implemented
code which will put (both ints) data from the two columns into their
respective text boxes.

What I need to also implement is being able to enter numbers into each
textbox and then, at the push of the button, have the cooresponding
row of the datagrid to be both highlighted and displayed. Other rows
can be visible as well, I just need the one which was 'manually
selected' via the text boxes to show up in the display of the datagrid
control and to be selected.

I have written the following code which works but it is slow and seems
clumsy:

while((Convert.ToInt32(dgMYDB[0,iCount].Value) ! = iID) ||
((Convert.ToInt32(dgMYDB[1,iCount].Value) != iCust)))

{
iCount++;
}

dgMYDB[ 0, iCount ].Selected = true;

There did not seem to be an intuitive way to get the functionality
beyond iterating through all of the entries in the manner that I have
shown above. Would anyone know of a more elegant solution for this?

Thank you for your consideration,

ewingate

Apr 16 '07 #1
2 1745
Consider making a datatable to hold the values and bind the grid to the
datatable, you can then use the select method of the table to find the rows
faster.
It uses complex hash buckets and things to hold the rows.
HTH

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"ew******@gmail.com" wrote:
I have a form with two text boxes, a button, and a datagrid control
which is bound to my SQL DB. There are two columns on the datagrid,
one for each of the textboxes on the form. I have already implemented
code which will put (both ints) data from the two columns into their
respective text boxes.

What I need to also implement is being able to enter numbers into each
textbox and then, at the push of the button, have the cooresponding
row of the datagrid to be both highlighted and displayed. Other rows
can be visible as well, I just need the one which was 'manually
selected' via the text boxes to show up in the display of the datagrid
control and to be selected.

I have written the following code which works but it is slow and seems
clumsy:

while((Convert.ToInt32(dgMYDB[0,iCount].Value) ! = iID) ||
((Convert.ToInt32(dgMYDB[1,iCount].Value) != iCust)))

{
iCount++;
}

dgMYDB[ 0, iCount ].Selected = true;

There did not seem to be an intuitive way to get the functionality
beyond iterating through all of the entries in the manner that I have
shown above. Would anyone know of a more elegant solution for this?

Thank you for your consideration,

ewingate

Apr 17 '07 #2
Thank you very much for you help. I am having a bit of trouble getting
that to work but I shall continue to work with the datatable approach.

-E

On Apr 17, 4:32 am, Ciaran O''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:
Consider making a datatable to hold the values and bind the grid to the
datatable, you can then use the select method of the table to find the rows
faster.
It uses complex hash buckets and things to hold the rows.

HTH

--
Ciaran O''Donnellhttp://wannabedeveloper.spaces.live.com

"ewing...@gmail.com" wrote:
I have a form with two text boxes, a button, and a datagrid control
which is bound to my SQL DB. There are two columns on the datagrid,
one for each of the textboxes on the form. I have already implemented
code which will put (both ints) data from the two columns into their
respective text boxes.
What I need to also implement is being able to enter numbers into each
textbox and then, at the push of the button, have the cooresponding
row of the datagrid to be both highlighted and displayed. Other rows
can be visible as well, I just need the one which was 'manually
selected' via the text boxes to show up in the display of the datagrid
control and to be selected.
I have written the following code which works but it is slow and seems
clumsy:
while((Convert.ToInt32(dgMYDB[0,iCount].Value) ! = iID) ||
((Convert.ToInt32(dgMYDB[1,iCount].Value) != iCust)))
{
iCount++;
}
dgMYDB[ 0, iCount ].Selected = true;
There did not seem to be an intuitive way to get the functionality
beyond iterating through all of the entries in the manner that I have
shown above. Would anyone know of a more elegant solution for this?
Thank you for your consideration,
ewingate- Hide quoted text -

- Show quoted text -

May 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Deep Silent Ocean | last post by:
Hi All I have one specific question for DataGrid In the Form Load event of the Form, I am binding data with DataGrid. On clicking Row the CurrentRowIndex is updated and it gives me correct...
6
by: aaa | last post by:
Hi I am trying to create a read-only DataGrid that would always have current row selected. Currently, I am using method: public void SelectDataGridRow(DataGrid dg) { if (dg.CurrentRowIndex >...
5
by: Dave | last post by:
Hi all, Apologies if this is the wrong group. I have done a search on google but my keywords are probably no good. What I want to do is to display a list of data in a datagrid (which I have...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
1
by: Dan | last post by:
I'd like to let a user select multiple rows from a Web Form datagrid, and then perform actions on the selected rows when I get a postback. How would I do that? Dan
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
0
by: rhepsi | last post by:
hii.. i have arequirement where... i want to update a field to N for the rows that are present in the datagrid... 1) strSQL = "UPDATE tbl_worker_profile SET " & _ ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.