How identify active control name

W

Woody Splawn

I know that I can do the following to identify the parent name of an active
control

Dim sParentName As String = ActiveControl.Parent.Name

But how do I identify the name of the active control?

Str = activeControl.Name

does not seem to work.
 
R

Rajesh Patel

it's should work. post your code snippet if you can't get it work.

Rajesh Patel
 
H

Herfried K. Wagner [MVP]

* "Woody Splawn said:
I know that I can do the following to identify the parent name of an active
control

Dim sParentName As String = ActiveControl.Parent.Name

But how do I identify the name of the active control?

Str = activeControl.Name

does not seem to work.

Why doesn't it work? Error message?
 
W

Woody Splawn

I'm sorry, I gave you incorrect information. It does work when I use it,
for example, on a txtbox on a field on a winform but I am trying to make it
work for a field on a datagrid. That is, I am on a datagrid and I would
like to identify the field on the datagrid that I am on. I assume that is
considered by VS as the ActiveControl. My intent is to leave it and then
return to it. When I use code like the following under those circumstances
I get a result of nothing.

Str = activeControl.Name

Dim sParentName As String = ActiveControl.Parent.Name gives me the name of
the datagrid but I would like the field on the datagrid that I am currently
on.

Thank you in advance for your help.
 
P

Peter Huang [MSFT]

Hi Woody,

Based on my understanding ,you want to know what field is the cell you are
selecting in.
I think you may try to get it from the datasouce. e.g. it is a dataset

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

MsgBox(DataSet11.Tables(0).Columns(DataGrid1.CurrentCell.ColumnNumber).Colum
nName)
End Sub

Did I misunderstand you meaning?
If you have related question, please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
P

Peter Huang [MSFT]

P

Peter Huang [MSFT]

Hi Woody,

Did my suggestion works for you?
If you have any related question, please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
X-Tomcat-ID: 195548074
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Tue, 14 Oct 2003 07:57:25 GMT
Subject: Re: How identify active control name
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Lines: 57
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:146476
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Woody,

Based on my understanding ,you want to know what field is the cell you are
selecting in.
I think you may try to get it from the datasouce. e.g. it is a dataset

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

MsgBox(DataSet11.Tables(0).Columns(DataGrid1.CurrentCell.ColumnNumber).Colu m
nName)
End Sub

Did I misunderstand you meaning?
If you have related question, please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Woody Splawn" <[email protected]>
References: <[email protected]>
Subject: Re: How identify active control name
Date: Mon, 13 Oct 2003 15:13:45 -0700
Lines: 22
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net 66.60.158.168
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:146430
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I'm sorry, I gave you incorrect information. It does work when I use it,
for example, on a txtbox on a field on a winform but I am trying to make it
work for a field on a datagrid. That is, I am on a datagrid and I would
like to identify the field on the datagrid that I am on. I assume that is
considered by VS as the ActiveControl. My intent is to leave it and then
return to it. When I use code like the following under those circumstances
I get a result of nothing.

Str = activeControl.Name

Dim sParentName As String = ActiveControl.Parent.Name gives me the name of
the datagrid but I would like the field on the datagrid that I am currently
on.

Thank you in advance for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top