开发者

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:

  1. The _CellEndEdit event is the wrong place to do such validation. You'd usually implement the _CellValidating event.
  2. If you must use _CellEndEdit to validate the inputs, you can try to use the EditingControl property of the DataGridView. 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.
  3. The DataGridViewCellValidatingEventArgs object passed to _CellEndEdit allows you to get the value that was entered and set the Cancel 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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜