472,373 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

Set Focus To Specific Property In Property Grid

I can set focus to my property grid by using propgrid.Focus - but how can I
set the default property that is always first? Or just set focus to the
default property? Can this be done?
Sep 27 '08 #1
10 4376
On Sep 27, 11:40*pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how canI
set the default property that is always first? Or just set focus to the
default property? Can this be done?
Hi Derek,

To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:

'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------
Hope this helps,

Onur Güzel
Sep 28 '08 #2
Thank you for the answer. Just need to add one thing to it. I am running
this code on the keydown event for a textbox control. It sets focus to the
grid properly now. But I need to trap the keystroke that was hit and fill it
in as the first character in the property, just like how Visual Studio works
when you are on a control and hit the first keyboard character and it starts
typing in the default property for that control. Is this possible?
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:d0**********************************@2g2000hs n.googlegroups.com...
On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how can
I
set the default property that is always first? Or just set focus to the
default property? Can this be done?
Hi Derek,

To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:

'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------
Hope this helps,

Onur Güzel
Sep 28 '08 #3
On Sep 28, 8:33*pm, "Derek Hart" <derekmh...@yahoo.comwrote:
Thank you for the answer. Just need to add one thing to it. I am running
this code on the keydown event for a textbox control. It sets focus to the
grid properly now. But I need to trap the keystroke that was hit and fillit
in as the first character in the property, just like how Visual Studio works
when you are on a control and hit the first keyboard character and it starts
typing in the default property for that control. Is this possible?

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:d0**********************************@2g2000hs n.googlegroups.com...
On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how can
I
set the default property that is always first? Or just set focus to the
default property? Can this be done?

Hi Derek,

To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:

'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------

Hope this helps,

Onur Güzel
As far as i understand (i couldn't guess well maybe), you're wanting
something like IntelliSense or setting the value of a property within
textbox, and setting PropertyGrid item's value outside PropertyGrid
control is not possible, because "Value" property is ReadOnly.

Or, my another guess that if you want to highlight a property grid
item which is inside PropertyGrid control while initial key matches
with the text in textbox you can use that:

'--------------Begin-------------
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown

Dim GridItem As GridItem = _
PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = _
GridItem.Parent
For Each egi As GridItem In _
pGridItem.GridItems
If egi.Label.StartsWith(e.KeyData.ToString) Then
PropertyGrid1.Focus()
egi.Select()
End If
Next

End Sub
'--------End----------

HTH,

Onur Güzel

Sep 28 '08 #4
Not quite. When I am in Visual Studio designing a form, and I highlight a
text box, when I then hit a letter, such as "T", it moves the cursor to the
property grid into the text property and enters "T" - then then user can
type the rest of the text in this property. Make sense?

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:fe**********************************@y71g2000 hsa.googlegroups.com...
On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
Thank you for the answer. Just need to add one thing to it. I am running
this code on the keydown event for a textbox control. It sets focus to the
grid properly now. But I need to trap the keystroke that was hit and fill
it
in as the first character in the property, just like how Visual Studio
works
when you are on a control and hit the first keyboard character and it
starts
typing in the default property for that control. Is this possible?

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:d0**********************************@2g2000hs n.googlegroups.com...
On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how
can
I
set the default property that is always first? Or just set focus to the
default property? Can this be done?

Hi Derek,

To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:

'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------

Hope this helps,

Onur Güzel
As far as i understand (i couldn't guess well maybe), you're wanting
something like IntelliSense or setting the value of a property within
textbox, and setting PropertyGrid item's value outside PropertyGrid
control is not possible, because "Value" property is ReadOnly.

Or, my another guess that if you want to highlight a property grid
item which is inside PropertyGrid control while initial key matches
with the text in textbox you can use that:

'--------------Begin-------------
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown

Dim GridItem As GridItem = _
PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = _
GridItem.Parent
For Each egi As GridItem In _
pGridItem.GridItems
If egi.Label.StartsWith(e.KeyData.ToString) Then
PropertyGrid1.Focus()
egi.Select()
End If
Next

End Sub
'--------End----------

HTH,

Onur Güzel
Sep 28 '08 #5
On Sep 29, 1:17*am, "Derek Hart" <derekmh...@yahoo.comwrote:
Not quite. When I am in Visual Studio designing a form, and I highlight a
text box, when I then hit a letter, such as "T", it moves the cursor to the
property grid into the text property and enters "T" - then then user can
type the rest of the text in this property. *Make sense?

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:fe**********************************@y71g2000 hsa.googlegroups.com...
On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
Thank you for the answer. Just need to add one thing to it. I am running
this code on the keydown event for a textbox control. It sets focus to the
grid properly now. But I need to trap the keystroke that was hit and fill
it
in as the first character in the property, just like how Visual Studio
works
when you are on a control and hit the first keyboard character and it
starts
typing in the default property for that control. Is this possible?
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message
news:d0**********************************@2g2000hs n.googlegroups.com...
On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how
can
I
set the default property that is always first? Or just set focus to the
default property? Can this be done?
Hi Derek,
To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:
'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------
Hope this helps,
Onur Güzel

As far as i understand (i couldn't guess well maybe), you're wanting
something like IntelliSense or setting the value of a property within
textbox, and setting PropertyGrid item's value outside PropertyGrid
control is not possible, because "Value" property is ReadOnly.

Or, my another guess that if you want to highlight a property grid
item which is inside PropertyGrid control while initial key matches
with the text in textbox you can use that:

'--------------Begin-------------
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown

Dim GridItem As GridItem = _
PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = _
GridItem.Parent
For Each egi As GridItem In _
pGridItem.GridItems
If egi.Label.StartsWith(e.KeyData.ToString) Then
PropertyGrid1.Focus()
egi.Select()
End If
Next

End Sub
'--------End----------

HTH,

Onur Güzel
Now got it what you desribe in VS. But couldn't associate your aim
with a textbox and typing in a defaul property of a propertygrid
control. For example, you can make a property default by using
"DefaultPropertyAttribute" in your class, for example you can design
your class whose default property is "Title" as follows:

<DefaultPropertyAttribute("Title")_
Public Class SampleProperty

Private _Title As String

<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Enter Title for the application")_
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal Value As String)
_Title = Value
End Set
End Property

Now, when you associate that class with PropertyGrid using:
"PropertyGrid1.SelectedObject = New SampleProperty" preferably in
form1_load event, "Title" property is pre-selected in gray and when
you type in a textbox using the code above, it gets focus in blue and
starts to type the value of that property.

Sorry, if i got wrong,

Hope this helps,

Onur Güzel
Sep 29 '08 #6
Not sure I understand how this will solve the problem. In Visual Studio, if
I design a text box, then highlight it and hit a keyboard character, it will
set focus to the property grid, and enter that character in the "text"
property waiting for more input. Can I recreate this somehow?
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:1a**********************************@f36g2000 hsa.googlegroups.com...
On Sep 29, 1:17 am, "Derek Hart" <derekmh...@yahoo.comwrote:
Not quite. When I am in Visual Studio designing a form, and I highlight a
text box, when I then hit a letter, such as "T", it moves the cursor to
the
property grid into the text property and enters "T" - then then user can
type the rest of the text in this property. Make sense?

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:fe**********************************@y71g2000 hsa.googlegroups.com...
On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
Thank you for the answer. Just need to add one thing to it. I am running
this code on the keydown event for a textbox control. It sets focus to
the
grid properly now. But I need to trap the keystroke that was hit and
fill
it
in as the first character in the property, just like how Visual Studio
works
when you are on a control and hit the first keyboard character and it
starts
typing in the default property for that control. Is this possible?
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message
news:d0**********************************@2g2000hs n.googlegroups.com...
On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yahoo.comwrote:
I can set focus to my property grid by using propgrid.Focus - but how
can
I
set the default property that is always first? Or just set focus to
the
default property? Can this be done?
Hi Derek,
To select(or focus) a pre-defined property in a PropertyGrid control
programmatically, you can use loop through GridItems and check "label"
to determine which item to be selected:
'------Begin-----
Dim GridItem As GridItem = PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = GridItem.Parent
For Each egi As GridItem In pGridItem.GridItems
If egi.Label = "property_label_here" Then
PropertyGrid1.Focus()
egi.Select()
End If
Next
'------End-------
Hope this helps,
Onur Güzel

As far as i understand (i couldn't guess well maybe), you're wanting
something like IntelliSense or setting the value of a property within
textbox, and setting PropertyGrid item's value outside PropertyGrid
control is not possible, because "Value" property is ReadOnly.

Or, my another guess that if you want to highlight a property grid
item which is inside PropertyGrid control while initial key matches
with the text in textbox you can use that:

'--------------Begin-------------
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown

Dim GridItem As GridItem = _
PropertyGrid1.SelectedGridItem
Dim pGridItem As GridItem = _
GridItem.Parent
For Each egi As GridItem In _
pGridItem.GridItems
If egi.Label.StartsWith(e.KeyData.ToString) Then
PropertyGrid1.Focus()
egi.Select()
End If
Next

End Sub
'--------End----------

HTH,

Onur Güzel
Now got it what you desribe in VS. But couldn't associate your aim
with a textbox and typing in a defaul property of a propertygrid
control. For example, you can make a property default by using
"DefaultPropertyAttribute" in your class, for example you can design
your class whose default property is "Title" as follows:

<DefaultPropertyAttribute("Title")_
Public Class SampleProperty

Private _Title As String

<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Enter Title for the application")_
Public Property Title() As String
Get
Return _Title
End Get
Set(ByVal Value As String)
_Title = Value
End Set
End Property

Now, when you associate that class with PropertyGrid using:
"PropertyGrid1.SelectedObject = New SampleProperty" preferably in
form1_load event, "Title" property is pre-selected in gray and when
you type in a textbox using the code above, it gets focus in blue and
starts to type the value of that property.

Sorry, if i got wrong,

Hope this helps,

Onur Güzel
Sep 29 '08 #7
"Derek Hart" <de********@yahoo.comwrote in message
news:eA**************@TK2MSFTNGP03.phx.gbl...
Not sure I understand how this will solve the problem. In Visual Studio,
if I design a text box, then highlight it and hit a keyboard character, it
will set focus to the property grid, and enter that character in the
"text" property waiting for more input. Can I recreate this somehow?
Remember that the PropertyGrid has an object assigned to it that serves as
the source of the data it displays. I think what you need to do is alter
that object so that your desired property now contains the character that
was typed and then set your focus to the PropertyGrid and the property.
Oct 2 '08 #8
Sounds like you want to use a macro in VS.

"Derek Hart" wrote:
Not sure I understand how this will solve the problem. In Visual Studio, if
I design a text box, then highlight it and hit a keyboard character, it will
set focus to the property grid, and enter that character in the "text"
property waiting for more input. Can I recreate this somehow?
Oct 3 '08 #9
Thanks for the different information. Just can't get it working. If I have
a textbox highlighted (remember, I am in runtime mode with custom code that
draws a rectangle around the textbox), then I hit a keystroke, it does set
focus to the property grid, and sets focus to the property.

Now I tried this code:
CType(propGrid.SelectedObject, PropertiesLabel).LabelName =
e.KeyData.ToString
propGrid.Refresh

So now when I hit a keystroke, it does fill in the first character into the
grid. But here is the tricky part. It does not open the property up for
editing. It sets focus to the property. Now the user hits another keystroke
and it types over the first one. Is is possible after the Refresh is done,
to open up the property for editing, and be in the second character
position?

"atalanta" <at******@discussions.microsoft.comwrote in message
news:9C**********************************@microsof t.com...
Sounds like you want to use a macro in VS.

"Derek Hart" wrote:
>Not sure I understand how this will solve the problem. In Visual Studio,
if
I design a text box, then highlight it and hit a keyboard character, it
will
set focus to the property grid, and enter that character in the "text"
property waiting for more input. Can I recreate this somehow?

Oct 4 '08 #10
"Derek Hart" <de********@yahoo.comwrote in message
news:O9**************@TK2MSFTNGP06.phx.gbl...
Thanks for the different information. Just can't get it working. If I
have a textbox highlighted (remember, I am in runtime mode with custom
code that draws a rectangle around the textbox), then I hit a keystroke,
it does set focus to the property grid, and sets focus to the property.

Now I tried this code:
CType(propGrid.SelectedObject, PropertiesLabel).LabelName =
e.KeyData.ToString
propGrid.Refresh

So now when I hit a keystroke, it does fill in the first character into
the grid. But here is the tricky part. It does not open the property up
for editing. It sets focus to the property. Now the user hits another
keystroke and it types over the first one. Is is possible after the
Refresh is done, to open up the property for editing, and be in the second
character position?
At this point you might have to dig into P/Invoke and just send a keystroke
to the property grid with the key_event() API function. If you look at the
PropertyGrid class in Reflector you find that there's a bunch of internal
and private stuff supporting its functionality, and I doubt you'll be able
to access them through the Framework. (Maybe if you derive from the grid?
But I doubt it....)
Oct 6 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Veeneman | last post by:
I couldn't find any postings on how to turn the VS.Net positioning grid on and off in the Google archives, so I'm adding this posting for future reference. The VS.Net positioning grid is...
7
by: Bill Todd | last post by:
I have a WinForms DataGrid bound to a DataView. I insert a new row by calling CurrencyManager.AddNew. However, the user cannot begin entering data until he/she clicks in the first cell of the new...
3
by: Eric Newton | last post by:
Given databinding an array of System.Version types: Given that "SomeObject" type has a Version property: public class SomeObject { public Version Version { get; } public string Description {...
0
by: Darrell Wesley | last post by:
I have one form with 2 panels. One of the panels has several radio buttons so that you can select one of several tables from a database. There are also 2 push buttons, one to retrive the data and...
0
by: Robert Jandorf | last post by:
I program using Visual Basic 6. I use the MSflexgrid for a schedule. I have it display times from 9:00 to 5:00 in 15 minute slots. There are too many appointments to viewed the entire day. It is...
3
by: Charles Law | last post by:
This is driving me mad. Can someone please put me out of my misery? I have a DataSet which I wish to use as the data source for a grid control (it is actually an Infragistics grid). When I assign...
10
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.