Windows Develop Bookmark and Share   
 index > Windows Forms General > Property grid setting focus to input field assosiated with grid item
 

Property grid setting focus to input field assosiated with grid item

HI,

I have a property grid i am able to set focus to particular griditem of property grid but i want to set focus to the assosiated input field with the seleted grid item.

Jogesh Grover  Thursday, July 05, 2007 7:06 AM

Hi, Jogesh,

I tried a lot, and I was able to achieve your goal by simulating a few "Key Press".

Please check the following codes

Code Snippet

Timer timer;

public Form2()

{

InitializeComponent();

propertyGrid1.SelectedObject = this;

propertyGrid1.Select();

"Cursor");//FindPropertyGridItem is my method to find the specified item.

timer = new Timer();

timer.Interval = 1;

timer.Tick += new EventHandler(timer_Tick);

timer.Start();

}

void timer_Tick(object sender, EventArgs e)

{

SendKeys.Send("{TAB}");

for (int i = 0; i < propertyGrid1.SelectedGridItem.Value.ToString().Length; i++)

{

SendKeys.Send("{LEFT}");

}

timer.Stop();

}

I'm not sure if it is the best solution, but I do hope it could be helpful for you.

Regards

Hi, Jogesh,

I'm not sure what does the "assosiated input field" stand for?

Do you mean the expanded field?

Regards

Yu Guo â€?MSFT  Wednesday, July 11, 2007 5:46 AM

Hi,

By assosiated input field i mean the textbox or editable area in front of property where we can see the cursor

Jogesh Grover  Wednesday, July 11, 2007 2:56 PM

Hi, Jogesh,

I think what you want is to get into edit mode, don't you?

We can done this as the following,

Code Snippet

propertyGrid1.SelectedObject = this;

propertyGrid1.Select();

propertyGrid1.SelectedGridItem = FindPropertyGridItem(propertyGrid1, "Cursor");//FindPropertyGridItem is my method to find the specified item.

propertyGrid1.SelectedGridItem.Select();

Hopes this helps,

Regards

Yu Guo â€?MSFT  Thursday, July 12, 2007 8:39 AM

HI Yu,

First of all thanks to you for sparing your valueable time.

Secondly, I think i was not clear

My Problem is i have a property grid in which i have properties like Length,Width,Diameter etc...

I have a Gridview in which i can see errors

Scenario is whenever i will enter any wrong value for property in the property grid i will get a error popped up in my grid view

For Ex:- If i will enter width as 20 and i am entering Length as 50 i will get a error in the grid view say

"Length can not be more than 50" or something like that

On click of that error i want to set focus to paritcular property which is generating error

In this case i want to set focus to Length property.

Now i am able to set focus to a particular property in the property grid [fig (a) below],

but i can not see the cursor blinking in front of the property like in [fig (b) below]

For Ex:-

(a) Length 50

(b) Length |50

i want to achive fig (b) instead of figure (a)

And i have seen your code snippet i think that will set focus to property grid item but not to the text areain front of it

Though your code is fine as it will set focus and without clicking on text area we can edit values but you know clients are clients he want the above thing, myclient wants to see the cursor blinking in the textarea whenver focus is set to a property

Jogesh Grover  Friday, July 13, 2007 9:58 AM

Hi, Jogesh,

I tried a lot, and I was able to achieve your goal by simulating a few "Key Press".

Please check the following codes

Code Snippet

Timer timer;

public Form2()

{

InitializeComponent();

propertyGrid1.SelectedObject = this;

propertyGrid1.Select();

"Cursor");//FindPropertyGridItem is my method to find the specified item.

timer = new Timer();

timer.Interval = 1;

timer.Tick += new EventHandler(timer_Tick);

timer.Start();

}

void timer_Tick(object sender, EventArgs e)

{

SendKeys.Send("{TAB}");

for (int i = 0; i < propertyGrid1.SelectedGridItem.Value.ToString().Length; i++)

{

SendKeys.Send("{LEFT}");

}

timer.Stop();

}

I'm not sure if it is the best solution, but I do hope it could be helpful for you.

Regards

Hi Yu,

Thanks man you are genius

you solved my problem i was struggling for this from so many days

Jogesh Grover  Monday, July 16, 2007 5:07 AM

You can use google to search for other answers

Custom Search

More Threads

• How to change Theme for desktop application
• Problem with setting an initial time value to Date Time Picker
• What's the difference between bin and obj?
• PrintPreviewDialog - PageCounter Not Displaying more than 1000
• Need to suppress or disable form events in code
• TextBox small problem...?
• Controls on the MDI parent
• How to identify the default language through C#.NET
• Windowbase application
• Hiding and expanding grids