Click to See Complete Forum and Search --> : Problem on setfocus


Debasis Bag
May 13th, 2010, 04:37 AM
Hi everybody,

I have a project which contains two forms.

One form contains a combobox and a datagridview control

2nd form contains a textbox and a command button and several Radio Buttons.

When I run the programme the 1st Form is loaded and it is displaying with a combobox and datagridview
If I select somethings from combobox the system showing 2nd form with three type ofcontols(textbox,command
button,radio buttons etc) on top of form No one.

Now I am selecting some radio buttos and clicking command button for execution some job then the 2nd form is closed and
1st form's datagrid view displaying some records and set focus goes to combobox not in gridview. as result
I can't do anything on gridview.

although I have written setfocus on gridview but still the focus goes to combo box
why setfocus is going to combo box instead of gridview.

Please suggest me how to setfocus on to gridview after clicking command button of 2nd form.

//Code
commandbutton_click

1stForm.Datagridview.focused()

//Code

Thanking you

Debasis

HanneSThEGreaT
May 13th, 2010, 06:26 AM
Maybe something else wrong, because this works perfectly :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
frm2.DataGridView1.Focus()
End Sub

DataMiser
May 13th, 2010, 08:18 AM
//Code
commandbutton_click

1stForm.Datagridview.focused()

//Code

The Focused() statement checks to see if the object has focus.
To set the focus to an object you use

Object.Focus

HanneSThEGreaT
May 13th, 2010, 08:45 AM
The Focused() statement checks to see if the object has focus.
To set the focus to an object you use

Object.Focus

Good eyes! :thumb:

Guess I didn't see it properly as Debasis Bag didn't put the the code in [CODE] tags, which has been asked a million times already.

Debasis, please, use [CODE] tags; it is explained here :

http://www.codeguru.com/forum/showthread.php?t=403073

It is really not difficult, and really not too much to ask of you...