datagrid

  • Thread starter Thread starter Angelina
  • Start date Start date
A

Angelina

Hiya,

I have just created a datagrid binded to a dataview (as i
wanted to limit the user from adding and editing rows in
the datagrid). What i want to be able to do now is for
the user to click anywhere on the grid but have the whole
row highlighted instead of just the single cell.
I would then like for the user to click a 'Remove' button
to delete the entire row from the database.

Can anyone plz help me do this or point me in the right
direction? I cannot seem to select the entire row :o(

Thank u all for your help.
 
Iv just managed to add some code that lets me select the
entire row
:o)
Now all i need is help coding a button that will remove
the selected row so that it is no longer displayed in my
database. The user should b shown a confirmation message
displaying the current row and asking if they are sure
they wish to delete it.

can anyone point me in the correct direction?
thx in advance
 
there are several ways of deleting a row in a db
or you send an sql command

SqlHelper.ExecuteNonQuery(gstrCnn, CommandType.Text, "DELETE FROM
tblArtgroepdeel WHERE artgdMainArtgID = " & g.ID)

or you create a stored procedure in the db like

CREATE PROCEDURE sp_deleteLotNr
@LotNr int
AS
delete from tblLotNrDetail where Lotnr = @LotNr
delete from tblLotNrGlobal where LotNr = @LotNr
return @@error
GO

and execute that
there are more ways of cource, but this might set you in the right
direction.

eric
 
seems i forgot the confirmation message, sorry.

If MessageBox.Show("Do you want to delete", "delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
'your deleting code here
End If

eric
 
Thanks Eric,

that is great. I just wanted to find out if the procedure
u gave me deletes the current selected row of the
datagrid. How does it know to delet this and no other row?
where is this specified? Also the code u gave me goes in
the onclick event for the 'Delete' button right?
 
Thanks Eric,

that is great. I just wanted to find out if the procedure
u gave me deletes the current selected row of the
datagrid. How does it know to delet this and no other
row?
where is this specified? Also the code u gave me goes in
the onclick event for the 'Delete' button right?
 
the messagebox code would go in your delete button
if you use a sql statement like
"DELETE FROM table1 WHERE column1 = " & VarID
it will delete all rows in table1 where the value in column1 is the same as
your variable VarID
if you are deleting single rows the best column you can use is the keycolumn
of the table

if you are using a stored procedure in an sql server you use a parameter in
there and in your vb code you call the stored procedure w the parameter

hope it helps

eric
 
Unfortunatly i cant use SPROCS as im using access xp.
I just wanted to know how i can delete the currently
highlighted row in the datagrid. How do i reference the
selected grid in thr datagrid? is there a property
like 'current row'? how would i integrate this into my
query? and would this query be written in the onclick
event?

i.e
delete roomNox from RoomTable
where roomIDx = CurrentlySelectedRoomIDfromDataGrid

RoomNoX represents a particular room number in my access
database.
Im confused on how to integrate the current select row
from the datagrid into my query i.e
CurrentlySelectedRoomIDfromDataGrid

Any Advice??
 
selected row in datagrid selected row is stored in the integer intRij in the
id you place the value of the first col
intRij = dgrMain.CurrentRowIndex()
intId = dgrMain.Item(intRij, 0)

sending sql statements to access i don't know, visual studio is not really
optimized for access, if i am in a situation where i can't use a real sql
server i normally use msde (a free small version of sql server)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmsde/html/msderoadmap.asp

eric
 
Back
Top