how to get FindControl Method in desktop application in C#
Hii
Iam not able to find the FindControl Method.this is the event "_CellEndEdit (object sender, DataGridViewCellEventArgs e)" in which Iam trying to access findControl....but开发者_StackOverflow中文版 I dont see that method...please tell me how can I access this method...
I believe FindControl
is a method on the Control
class in the System.Web.UI
namespace. In WinForms, you don't require this.
What control are you trying to find? Is it a grid editing control?
Will you use this control to get the cell value?
Update: the cell value is presented on the cell itself, there is no need to find the control underling the cell. The event arguments either contain the cell itself, the value itself, or the RowIndex
and ColumnIndex
. Using the latter, you can get the cell from the grid and review its .Value
property:
DataGridViewCell c = grid[colIndex, rowIndex];
Note also there is a CellValidating
cancellable event on the grid that sounds more suitable to your needs.
The FindControl
method is only available for instances of the Control
class and its descendants. So you could call it on the form like
this.FindControl(...);
EDIT
As for your comment:
- The
_CellEndEdit
event is the wrong place to do such validation. You'd usually implement the_CellValidating
event. - If you must use
_CellEndEdit
to validate the inputs, you can try to use theEditingControl
property of theDataGridView
. This should return the current editing control for the cell if the cell is in edit mode. However, it may be that the_CellEndEdit
event is called after the edit control is already destroyed. - The
DataGridViewCellValidatingEventArgs
object passed to_CellEndEdit
allows you to get the value that was entered and set theCancel
property (maybe along with a cell error), so that the changes are cancelled.
You can use the Control.ControlCollection.Find method.
i.e:
this.Controls.Find()
精彩评论