Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to set focus in a grid 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
0
0
US
I am usign a datagrid and the first column is locked. I have set the tab index for the grid to 0. how can i set focus to the second column of the grid?? since the first one is locked I need it to go to the second column..


Thanks dvannoy@onyxes.com
 
I am getting an Invalid procedure call or argument...
cant set focus to the grid... dvannoy@onyxes.com
 
In the DataGrid properties, is enabled set to true? If so, you should be able to set focus. I have a similar situation and I did it this way:

With DataGrid1
.SetFocus
If .CurrentCellVisible = False Then 'tab over to the next column
SendKeys "{TAB}"
End If
End With
 
Enabled is set to true..It still wont let me set focus..the first column is locked and the tab index is set to 0..if I unlock the column it will go right to the first column no problem. it must have something to do with the first column being locked...when I open the grid and hit tab, it will then jump to the second column but I cannnot set focus to the second column..
dvannoy@onyxes.com
 
When you say that the first column is locked, what do you mean? Is there a property that you're using to do this?
 
This is for the first column

With DrmDataGrid
.Columns(0).Caption = "Cont#"
.Columns(0).Alignment = dbgCenter
.Columns(0).Width = 600
.Columns(0).Locked = True
etc...


I need the first colunmn (Column 0) to be locked..

dvannoy@onyxes.com
 
try to invoke dbgrid_HeadClick(1) event manualy
 
how do I do that?? never heard of that dvannoy@onyxes.com
 
Ok...that worked, but there is still another problem. and this may be a VB thing.. the code I have in the load event of the form to set the focus on a column in the grid works fine now.. but I also have a button that does the same thing as the load event and the grid will lose focus. I have tryed Refresh etc.. after clicking the button you can see the cursor move to the column I want to set focus to..but then it jumps back to the locked column(0).. I have tryed moving the code around and nothing works..

Like I said, this could be a VB problem.

Thanks dvannoy@onyxes.com
 
Can you post your code - the Form Load Event and the Click Event of the Command Button. Maybe something will jump out at me.
 
Private Sub Form_Load()

Dim sName As String

strCn = "driver={SQL Server};" & _
"server=;uid=sa;pwd=;" & _
"database=test"

Set cn = New ADODB.Connection

With cn
.ConnectionString = strCn
.Provider = "msdasql"
.ConnectionTimeout = 60
.Open strCn
End With

sName = Trim(InputBox$("Please Enter Documnet# Below..", "Search for Document")) '& "%"

sName = Trim$(sName) & "%"

strRs = "SELECT * FROM TABLE1 WHERE Document LIKE '" & sName & "'"

Set rs = New ADODB.Recordset

rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
rs.LockType = adLockPessimistic
rs.Open strRs, strCn

strGrid = "Select ddhunb,spg,totalgal,drmsize,h20,reliq,sdpo,sdebris,drmcond FROM AS400 WHERE Document LIKE '" & sName & "'"

Set rsGrid = New ADODB.Recordset
rsGrid.CursorType = adOpenDynamic
rsGrid.CursorLocation = adUseClient
rsGrid.LockType = adLockPessimistic
rsGrid.Open strGrid, strCn
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Me.DrmDataGrid.Col = 1
SetDrumInfoText
frmDrumInfo.Top = (Screen.Height - frmDrumInfo.Height) / 2.7
frmDrumInfo.Left = (Screen.Width - frmDrumInfo.Width) / 2

Set DrmDataGrid.DataSource = rsGrid
rscount = rs.RecordCount
txtQty.Text = rscount
lblqty1.Caption = "Line Item QTY - " & rscount & " " & txtType.Text & ""

SetDrumCheckerGrid

txtCustomer.Locked = True
txtDocument.Locked = True
txtWip.Locked = True
txtDateReceived.Locked = True
txtType.Locked = True

Else
MsgBox "Document was not found", vbInformation
Exit Sub
End If

End Sub


Private Sub cmdSearch_Click()

Dim sName As String

strCn = "driver={SQL Server};" & _
"server=;uid=sa;pwd=;" & _
"database=test"

Set cn = New ADODB.Connection

With cn
.ConnectionString = strCn
.Provider = "msdasql"
.ConnectionTimeout = 60
.Open strCn
End With

sName = Trim(InputBox$("Please Enter Document# Below..", "Search for Document")) '& "%"

sName = Trim$(sName) & "%"

strRs = "SELECT * FROM TABLE WHERE Document LIKE '" & sName & "'"

Set rs = New ADODB.Recordset

rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
rs.LockType = adLockPessimistic
rs.Open strRs, strCn

strGrid = "Select ddhunb,spg,totalgal,drmsize,h20,reliq,sdpo,sdebris,drmcond FROM AS400 WHERE Document LIKE '" & sName & "'"

Set rsGrid = New ADODB.Recordset
rsGrid.CursorType = adOpenDynamic
rsGrid.CursorLocation = adUseClient
rsGrid.LockType = adLockPessimistic
rsGrid.Open strGrid, strCn
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Me.DrmDataGrid.Col = 1
SetDrumInfoText

Set DrmDataGrid.DataSource = rsGrid

rscount = rs.RecordCount
txtQty.Text = rscount
lblqty1.Caption = "Line Item QTY - " & rscount & " " & txtType.Text & ""

SetDrumCheckerGrid

txtGenerator.Locked = True
txtManifestNo.Locked = True
txtWip.Locked = True
txtDateReceived.Locked = True
txtType.Locked = True

Else
MsgBox "Document was not found", vbInformation
Exit Sub
End If


its the same code...It should work I dont know why..


Thanks

End Sub dvannoy@onyxes.com
 
Sorry dvannoy - I was hoping that something would jump out at me, but the code looks exactly the same for both Click Events (as you said). Good luck finding a solution. If I run across anything, I'll post again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top