Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi masters
i have a win application and form with datagridview
i want when value of 1 cell is changing call a method.
i use cellvaluechanged event but call my method after leave cell or press enter.
help please..
thanks
Posted
Updated 2-Jul-15 18:28pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Jul-15 16:16pm    
"*Changing", in contrast to "*Changed", is based only one feature: the ability to cancel the change and leave the value as it was before. There is no such event. But if this is what you wanted, and if you explain your idea and your ultimate goals, we will try to help you.
—SA
Ehsanf3 3-Jul-15 0:26am    
i have a datagridview with 5 columns from a table(tbl1) .. one this columns is a foreign key from another table(tbl2)... in another form customer enter data of tbl2
and use them in tbl1 ... i want when customer click on this column show a listview with data on tbl2... and when typing a value to this column search that like auto complete in combobox and show search result in listview
Sergey Alexandrovich Kryukov 3-Jul-15 0:30am    
I added a new tag to your question. You should always explicitly indicate your UI framework/library.
Could you tell me: what's wrong with simply using combo box System.Windows.Forms.DataGridViewComboBoxColumn instead?
You did not answer my question: why "changing"? Where you are going to cancel the change? I cannot see it in your requirements. Therefore, it could be "changed".
—SA
Ehsanf3 3-Jul-15 0:59am    
"changing" because i want to search when customer changing this cell value
i can not use ombo box System.Windows.Forms.DataGridViewComboBoxColumn with auto complete currently.. i want to customer can enter id and name of values in this cell then i search that and show... can i use combobox for this cell ?
Sergey Alexandrovich Kryukov 3-Jul-15 1:02am    
I'm asking again: where in your requirements you need to cancel the change? If you don't need it, you can use "changed" event. How many times I have to explain this difference?
Also, you still did not answer why not using System.Windows.Forms.DataGridViewComboBoxColumn.
—SA

In your comments to the question, you made it clear that you don't need to cancel the change. It means that you don't need that non-existing event which is invoked when the data is about to change, traditionally called "*Changing"; it would be enough to catch the event when the data is changed: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged%28v=vs.110%29.aspx[^].

However, you still may need to change some data associated to the cell when editing is just started. You can also use the event CellBeginEdit/CellEndEdit and/or CellEnter. Please see:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellbeginedit(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellendedit(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellenter(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview_events%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
What about the following :
When you select a cell for editing you open a Dialog which allows you (or the Operator) to modify the value in a TextBox. The TextBox gives you a TextChanged Event for every change inside the box. With this Event you could modify the other control.
If editing is finished the Dialog writes it's Input back to the cell ...
 
Share this answer
 
I have an idea u can write a change method yourself. Create a timer to compare the current value of the certain cell to the old one, if changed then call your change method.......
 
Share this answer
 
Comments
Ralf Meier 2-Jul-15 5:41am    
A Changed-Event is still existing at the DGV.
The Thread-Starter wants (so I suppose) to detect the Changing itself.
Of course ... that could be done by your Suggestion by customizing the DGV ... But better will be, if an existing Event could be used ...
Sergey Alexandrovich Kryukov 3-Jul-15 0:32am    
The inquirer asked about "changing", but did not explain what's wrong with "changed". Please see my comment to the question.
As to the present "answer", it's hard to invent anything worse.
—SA
Ehsanf3 3-Jul-15 0:28am    
yes if use existing event its better
Sergey Alexandrovich Kryukov 3-Jul-15 0:31am    
It's hard to invent anything worse than that. It's clearly the vote of 1. It's so apparent...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900