Tabbing between radio buttons in VB6 - vb6

I have a form which consists of six radio buttons within a frame which are mutually exclusive and one command button.
I already gave different tab-index to each radio button but at the run time by pressing tab focus skipped out of the radio buttons.
so how to give focus to another radio button by pressing TAB?

As others have said above this is intended behaviour. If you really wish to achieve this then the only way I can think to do this is place each radio button on a separate picture box (BorderStyle = None, TabStop = False). This will then work but you won't be able to use arrow keys to move between the radio buttons, only tabbing.

Private Sub Option1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Option2.SetFocus
End If
End Sub
KeyAscii=9 is the code for the Tab key. But you must do it for all of your radio buttons.
If you add your radio buttons belonging to the same radio button having indices 0, 1, 2 you can do it like this:
Private Sub Option1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 9 Then
If Index < Option1.Count - 1 Then
Option1(Index + 1).SetFocus
Else
Option1(0).SetFocus
End If
End If
End Sub

Related

Unable to allow row selection on click over mshflexgrid control in vb6

The form that has mshflexgrid control is not allowing to select the row on which the mouse click has done. Sometimes it allows selection of previous row and not the row which is been clicked
I have tried adding one to the property .RowSel of mshflexgrid to allow the row selection, it is not working for second row selection.
Private Sub MSHFlexGrid1_Click()
last_row_selected = MSHFlexGrid1.RowSel
If last_row_selected <> 1 Then last_row_selected = last_row_selected + 1
With MSHFlexGrid1
If (boolShift And vbShiftMask) = vbShiftMask Then
SelectionOneAfterTheOther
ElseIf (boolShift And vbCtrlMask) = vbCtrlMask Then
SelectUnSelectGridRow
Else
UnSelectAllGridRows
.Row = last_row_selected
.ColSel = .Cols - 1
.CellBackColor = vbHighlight
.CellForeColor = vbHighlightText
End If
End With
MSHFlexGrid1.Refresh
End Sub
It seems that the .RowSel property isn't taking correct value for selection of row
The result needs to be proper selection of row on which it is clicked.
In your grid Click event, try something like this:
With MSHFlexGrid1
If .Row = .RowSel Then
.Col = .Cols - 1
.ColSel = 0
End If
End With
You may need to set SelectionMode on the grid control also. The above code should work if set to flexSelectionFree
Have you set the SelectionMode property? If not, you get to it by clicking "Custom" in the properties window. This opens a dialog where SelectionMode is one of the available properties.

Programatically click a row in a listbox

When I click the a command button to close the form, the code requery's a cbo and listbox, moves the focus to the lstbox and a particular row. What I need to do is add some code that "clicks" the current row in the listbox that has the focus.
Here is the code I have on the click event.
If Forms![frmmain]![txtHidden] = "addok" Then
Forms![frmmain]![cboAuthor].Requery
Forms![frmmain]![LstAuthor].Requery
Forms![frmmain]![LstAuthor] = Me.AuthorID
Forms![frmmain]![txtHidden] = "AddDone"
DoCmd.Close acForm, "frmAddAuthorFly"
Forms![frmmain]![cboAuthor].Requery
Forms![frmmain]![LstAuthor].Requery
Forms![frmmain].[LstAuthor].SetFocus
<NEED TO INSERT SOMETHING HERE TO CLICK THE ROW"
Else
MsgBox "txt hidden is not addok"
DoCmd.Close acForm, "frmaddauthorfly"
End If
A click does nothing by itself, but you may have some OnClick code that runs. To do so, just call the OnClick event.
But all this requiring - and indeed "clicking" - shouldn't be needed; it seems as if you need to rethink your concept.

Scroll Bar Issues Automatically Scrolling Down To The Last Control

Alright, I designed a form to fit onto the current screen size I use, with the form having a vertical scroll bar to view items further down on the form.
At the bottom of the form, I have a couple of checkboxes a user has to select before clicking the submit button.
Once the user hits the submit buttom, the user can't scroll back up to the beginning of the form. The user can scroll back up, but when they stop scroll, it scrolls to the bottom where the last checkbox was checked off.
I assume by checking this last checkbox is that's setting the focus of that control?
Any suggestions on how to fix the scrolling issue?
Keep a note of the last scroll position, and reapply it on Form_Activate
Try this:
'' Declare at form level
Private LastAutoScrollPos As System.Drawing.Point
Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
Me.AutoScrollPosition = LastAutoScrollPos
End Sub
Private Sub Form1_Scroll(sender As Object, e As System.Windows.Forms.ScrollEventArgs) Handles Me.Scroll
If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then
LastAutoScrollPos = New Point(LastAutoScrollPos.X, e.NewValue)
ElseIf e.ScrollOrientation = ScrollOrientation.HorizontalScroll Then
LastAutoScrollPos = New Point(e.NewValue, LastAutoScrollPos.Y)
End If
End Sub

call a toolbar button click from another form

In VB6 I need to know how to call a button click event on anther form. The another form part is easy but how to pass the click event the proper method to "click" the right button on the toolbar is the real issue.
Here is the vent on the main form - i need to call the click event case "Copyfrom".
MainForm
Public Sub tbrMain_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case ToolBarItem.tbPrint
'(some code)
Case ToolBarItem.tbSave
'(some code)
Case ToolBarItem.tbCopyFrom
'(some code)
Case ToolBarItem.tbNEW
'(etc)
I tried
Mainform.tbrMain_ButtonClick()
and even tried passing the index number and key - no dice.
The event handler is expecting to receive a reference to an actual toolbar button, so you have to pass the toolbar button itself, not it's Caption or Key, e.g.:
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons(1)
Or, using the Call statement:
Call Form1.tbrMain_ButtonClick(Form1.tbrMain.Buttons(1))
If you set the Key properties on your toolbar buttons, you can use the Key property of the desired button in place of the (1):
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons("PrintButton")
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
If ButtonMenu.Key = "A" Then
MsgBox "Button-1"
ElseIf ButtonMenu.Key = "B" Then
MsgBox "Button -2"
ElseIf ButtonMenu.Key = "C" Then
MsgBox "Button -3"
ElseIf ButtonMenu.Key = "D" Then
MsgBox "Button -4"
ElseIf ButtonMenu.Key = "E" Then
MsgBox "Button -5"
End If
End Sub

Lists box manipulation on button click in VB 6.0

Hello
I am doing a small I.T assignment where we have to create a database library type borrowing system and I have two list boxes listbox 1 is where all the games are listed and you can chose to borrow them the other one is where the games go to after you click the button that transfers them to listbox 2.
Aso how can I add a button that when you click it adds a new Item (game) to the first listbox and so you can borrow that one two
Thank you for your help.
Assuming two list boxes (listbox1 and listbox2) and a command button (cmd1) on a VB 6 form named Form1
private sub Form_Load()
listbox1.AddItem "game 1"
listbox1.AddItem "game 2"
listbox1.AddItem "game 3"
end sub
Private Sub cmd1_click ()
If listbox1.listindex >-1 then
'Add the selected item from listbox1 to list box 2
listbox2.AddItem listbox1.List(listbox1.ListIndex)
'Remove selected item from listbox1
listbox1.removeitem(listbox1.listindex)
End If
End Sub

Resources