Selecting rows on a datagrid via code

E

ewingate

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
 
G

Guest

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
 
E

ewingate

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



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



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 -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top