Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check to see if a datagrid item has been selected 1

Status
Not open for further replies.

ietprofessional

Programmer
Apr 1, 2004
267
0
0
US
How do you check to see if a datagrid item has been selected?

I'm creating a editing form where a user will click a update button and if they didn't select a item in the datagrid I want them to receive a message, but I'm not sure how to check and see if a item has been selected in the datagrid.

If they do select an item in the datagrid the values will fill the textfields where they will update them and click the update button.

Thanks!
 
If the selection on the datagrid is what populates the textboxes (rather than a button click), then the update button won't need to check if a row in the datagrid is selected. may be a simpler approach...
 
correct, just use validation of the text boxes with the update button...if there is no data in the boxes (or in an ID hidden field) then return a message stating that the user must select something from the datagrid...I'm assuming you're using radio buttons within the datagrid?
 
That won't work because I'm giving them two options select a item in the datagrid and update the selected item by clicking the update button or add new item and click add new button.

All I need is to be able to check if something is being selected so my code doesn't go through the update sql without a primary key(datakey value).
 
Can you just use the datagrid as updateable?

and if you used a hidden field for an id from the datagrid you could use validation on the button that says...
Code:
if id = 0 then
  'add new record
else
  'update selected record
end if
 
How do you check to see if a datagrid item has been selected?
How do you define "selected"? Is there a checkbox/radiobutton in each row?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
On click of the add new button:

1. DataGrid1.SelectedIndex = -1 (this clears the datagrid selection to avoid confusion to the user.)

2. set all the text properties to "" for your textboxes.

3. hide the update button and show the add button.


I guess you could also check if the SelectedIndex is -1 to determine if there is or isn't a selection...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top