Handle select click event datagridview - c#

My WinForm project in c#, I have DataGridview that i want to disable cell selection with mouse clicking in editing.
To be more specific; when the user keypress"=" en event fired and disable to select cell by clicking.I want to do something different instead of cell selection. Only by keypressing"ESC" or "Enter" allow to leave cell editing.
I added picture for understanding.Please help.

Related

How to trigger a button event while checked status change for checkbox

I want to generate button click event while checking checkbox in data grid view. How it this possible?
I put my perform click event in dataGridView1_CellContentClick.
When I click on any row first time button event could not perform, however when I click other row then it will perform a button click event for first row click. How to solve this issue?
If you want to know when anywhere in the cell is clicked, then its best to use CellClick or probably CellMouseDown.
If you are not after whitespace in the row or column then its best to use CellContentClick (for columns like checkbox, button, link etc)..

Asp.net Keydown Event not always fired within GridView

Within a griview (using IE), cells in one column are clickable (through gridview row command event) and once a cell is clicked it displays a hidden textbox (visible = false before the cell is clicked); users can enter text into the textbox and to allow saving changes made to the textbox users are told to press Tab key.
The saving is done through using Javascript by checking keycode in keydown event, it simply checks when keycode = 9 (Tab key) __doPostback('OnClick','SaveButton'); in codebehind SaveButton onclick event simply calls a store procedure to save the new text changes into database.
The problem I have is keydown event is not ALWAYS fired though it works most of the time. There seems to be no difference to the situation when it works and when it doesn't, so to me it's a bit random and I have to emphaise that it works 90% of the time.
Worth mentioning that when users click the cell to edit the textbox, gridview row updating event is fired first since I need to enable gridview row updating event not only for this column text changes but also for other columns data updating.
When everything 'works' after user pressing the Tab key, the event sequence is:
Gridview row updating
Keydown/SaveButton click
Gridview row updating
I don't understand what triggers the event 3 i.e. the second gridview row updating event though it doesn't do any harm to anything as it's after the text being saved into database. But when pressing Tab key doesn't work (text not saved) the second gridview row updating event is not fired; only the 1st row updating event is fired and textbox changes are lost reverting back to the original text.
I'm new to asp.net and hope someone can shred some light on this problem.
I found out why GridView row updating event fired for the 2nd time, it's because AutoPost for the editable textbox being set to True.
silly me...

datagridview pans on clicking a cell

I have a winforms application that has a datagridview control. Now, when I click on a cell in the datagridview control, the view shifts/pans the datagridview control, such that the cell selected is more or less in the centre of the screen. Is there any way to disable this? My users find this irritating.
The data gridview is essentially needed only to show colour codes (i.e. no text) and tooltips for each cell. I have tried
datagridView1.Enabled = false;
This solves my problem, however, I can no longer view the tooltip text.
Is there any other work-around? Is it possible to prevent the user from clicking on a cell in the first place to prevent this?

DataGridView - Delete items with ContextMenu

I am currently developing an DataGridView to store PDF-Files via Drag and Drop.
The user is able to d'n'd the file into the DataGridView and the PDF is stored to an container.
Then I wanted to realize a ContextMenu which allows the user to open or delete the PDF by right clicking on it and selecting the targeted option.
The option "Open" is working fine by using the HitTest(x, y) with the CursorPosition.
My problem is, that as you see the "Delete" button is placed in the cell bellow and the HitTest(x, y) will deliver me the cell right below, which is not my goal.
What I have tried
I've tried it by catching the CellContentClick and Click events, but those are not triggered by right clicking the cell. Also the option by saving the last entered cell by catching the CellMouseEnter event is not working propably
Is there any posibility to get to know which cell was right clicked?
In Your dataGridView enable the Single Cell Selection property and then on click of your context menu you can get the selected cell
You can get the selected cell by
private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
dataGridView.CurrentCell = dataGridView[e.ColumnIndex, e.RowIndex];
}
}

How to make popup window appear when double click on a cell in datagrid

I have a data grid displaying results from a sql database. What I want to do is make it so that when I double click on a cell in the datagrid, a new window appears where that cell can be edited. I also would like to have all the info for that cell to be autogenerated into editable fields when the cell is double clicked. Any help or links to tutorials is appreciated. Thanks.
Add an onclick event that opens the window to the cell (using datagridview would be a good idea I think).
In addition, you you just want them to edit the cell contents, you can let the control handle all that for you (enable editing, adding, deleting, etc if you want).
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.onclick.aspx

Categories

Resources