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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

overloading DataGrid to not allow deletion of row

Status
Not open for further replies.

kmfna

MIS
Sep 26, 2003
306
US
Hello all, Its been a while since I've been able to visit this wonderful exchange of knowledge, so first off, just wanted to say, "Hi, its good to be back".

Anyway, I am having a minor issue. I want to stop a user from deleting a row in a datagrid (windows form, not asp) for various reasons and thought that someone may have some ideas about hot to stop them before they start. I have the class overridden to change enter keys to tabs, and was hoping to capture when they press the Delete Key, however, I couldn't get it to capture it, so I couldn't circumvent it. Anyway, if anyone has any ideas, please let me know.

Thanks a bunch.
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Jish,

Thanks for helping out, however that did not keep me from deleting a row out of the datagrid. Any other ideas?? Anyone else have any ideas??? I have tried messing with the tablestyle that I have on the grid, but there did not seem to be any controls that I could use to preempt deletion. Maybe a way to keep them from selecting the entire row, so they couldn't just delete it??

Anyway, thanks in advance,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Sorry,

yeah, they need to be able to add and edit, just not delete...I also tried adding an overload for for rowdeleting, but didn't know how to stop it....

Thanks,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
An easy solution is to set RowHeadersVisible to false in the DataGridTableStyle of the DataGrid;
Code:
DataGridTableStyle vStyle = ...;
vStyle.RowHeadersVisible = false;
On the CurrentCellChanged event handler, capture grid navigation using keys and mouse.
-obislavu-
 
hello all,

Thanks for your help, but I finally figured out how to do what I wanted....I already had the datagrid overloaded, so I simply captured the Delete key and sent back a blank space...I had to do that, because just returning true actually kept them from deleting data from inside the cells, so with the blank space I can just capture the cell and trim the space out and voila, it worked!! :)

Thanks again,
kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top