First Button on Toolbar Has No Caption 
Author Message
 First Button on Toolbar Has No Caption

My first posting to a group--here goes...

I'm reading data from a table (in VB6) and dynamically creating a toolbar,
showing both an icon and a caption.

If the toolbar has two or more buttons on it, all looks fine.

If the toolbar has only one button, the caption does not appear.

Here's part of the code:

Do Until rs.EOF
    'get the app icon associated with this file name extension
    sImageKey = GetDocumentIconKey(rs("FILEPATH"))
    'extract file name from full path, to use as caption for button
    iPos = InStrRev(rs("FILEPATH"), "\")
    If iPos > 0 Then
        sFileName = Mid(rs("FILEPATH"), iPos + 1)
    Else
        sFileName = rs("FILEPATH")
    End If
    Set btnButton = Toolbar1.Buttons.Add(, , sFileName, tbrDefault, sImageKey)
    btnButton.ToolTipText = rs("FILEPATH")
    rs.MoveNext
Loop

Toolbar properties (relevent or otherwise):
Align - none
AllowCustomize - False
Wrappable - True
ShowTips - True
BorderStyle - none



Mon, 20 Sep 2004 07:16:56 GMT  
 First Button on Toolbar Has No Caption
If you change the ToolTipText to the value in sFileName instead of
rs("FILEPATH"), does a valid item show up when you mouse over the single
button?  I tried your code (without the recordset), and with VB6 I had no
problem setting the text of a single button. My first guess would be that
either the rs is returning nothing for the first item, or that your If...
test is somehow nuking the contents.

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.

Quote:

> My first posting to a group--here goes...

> I'm reading data from a table (in VB6) and dynamically creating a toolbar,
> showing both an icon and a caption.

> If the toolbar has two or more buttons on it, all looks fine.

> If the toolbar has only one button, the caption does not appear.

> Here's part of the code:

> Do Until rs.EOF
>     'get the app icon associated with this file name extension
>     sImageKey = GetDocumentIconKey(rs("FILEPATH"))
>     'extract file name from full path, to use as caption for button
>     iPos = InStrRev(rs("FILEPATH"), "\")
>     If iPos > 0 Then
>         sFileName = Mid(rs("FILEPATH"), iPos + 1)
>     Else
>         sFileName = rs("FILEPATH")
>     End If
>     Set btnButton = Toolbar1.Buttons.Add(, , sFileName, tbrDefault,
> sImageKey)     btnButton.ToolTipText = rs("FILEPATH")
>     rs.MoveNext
> Loop

> Toolbar properties (relevent or otherwise):
> Align - none
> AllowCustomize - False
> Wrappable - True
> ShowTips - True
> BorderStyle - none



Mon, 20 Sep 2004 09:48:43 GMT  
 First Button on Toolbar Has No Caption

Quote:
>My first posting to a group--here goes...

Welcome to the group, Brian.

Quote:
>If the toolbar has only one button, the caption does not appear.
>Here's part of the code:
>Do Until rs.EOF
>    'get the app icon associated with this file name extension
>    sImageKey = GetDocumentIconKey(rs("FILEPATH"))
>    'extract file name from full path, to use as caption for button
>    iPos = InStrRev(rs("FILEPATH"), "\")
>    If iPos > 0 Then
>        sFileName = Mid(rs("FILEPATH"), iPos + 1)
>    Else
>        sFileName = rs("FILEPATH")
>    End If
>    Set btnButton = Toolbar1.Buttons.Add(, , sFileName, tbrDefault, sImageKey)
>    btnButton.ToolTipText = rs("FILEPATH")
>    rs.MoveNext
>Loop

Looks ok to me. I guess, you would have already debugged that the
string you're assigning is valid.. so i won't even mention it.  :)
Does your code go into something intensive after this. like a long
loop ?  Sometimes that can prevent the controls to refresh.
Try a DoEvents or a ToolBar1.Refresh after rs.MoveNext.

ps: If your database fields are fixed length, you may want to Trim
them, otherwise you're adding all the padding as well..

Regards, Frank



Mon, 20 Sep 2004 10:54:28 GMT  
 First Button on Toolbar Has No Caption


Quote:

>>My first posting to a group--here goes...

>Welcome to the group, Brian.

You too Barry. ;-)
Whoops. :)

Regards, Frank



Mon, 20 Sep 2004 11:06:58 GMT  
 First Button on Toolbar Has No Caption
Thanks for your suggestions. I tried them all:
- setting ToolTipText to sFileName
- ensuring the recordset was correct (that I was not assigning a null to the
  caption of the first button)
- DoEvents after creating each button
- Refresh after creating each button, on both the toolbar and the form

Then I tried:
- creating a dummy button in design mode, and removing all buttons added in
  code except the dummy button each time I rebuilt the toolbar; both the
  dummy button and the lone button added in code had no caption
- putting a 'placeholder' button on the toolbar first
- adding the first button twice, then removing the index-1 button after the
  toolbar is built
- adding the first button twice, then removing the index-2 button after the
  toolbar is built

None of this worked. Something is preventing the caption from appearing on
the first button added in code, until a second button is added. Removing this
second button makes the first button's caption disappear.

Quote:

> My first posting to a group--here goes...

> I'm reading data from a table (in VB6) and dynamically creating a toolbar,
> showing both an icon and a caption.

> If the toolbar has two or more buttons on it, all looks fine.

> If the toolbar has only one button, the caption does not appear.

> Here's part of the code:

> Do Until rs.EOF
>     'get the app icon associated with this file name extension
>     sImageKey = GetDocumentIconKey(rs("FILEPATH"))
>     'extract file name from full path, to use as caption for button
>     iPos = InStrRev(rs("FILEPATH"), "\")
>     If iPos > 0 Then
>         sFileName = Mid(rs("FILEPATH"), iPos + 1)
>     Else
>         sFileName = rs("FILEPATH")
>     End If
>     Set btnButton = Toolbar1.Buttons.Add(, , sFileName, tbrDefault, sImageKey)
>     btnButton.ToolTipText = rs("FILEPATH")
>     rs.MoveNext
> Loop

> Toolbar properties (relevent or otherwise):
> Align - none
> AllowCustomize - False
> Wrappable - True
> ShowTips - True
> BorderStyle - none



Tue, 21 Sep 2004 02:53:20 GMT  
 First Button on Toolbar Has No Caption
That is weird. Can you email me a demo that repro's this without requiring
data access .. just the toolbar code setting a dummy caption - say three
buttons - one to add one button & caption, one to add two with captions, and
one to remove the second button (to repro the button loosing the caption).
I'll see if it works here. (Does it work if you do not bind an imagelist to
the control, and remove the icon index param?)

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.

Quote:

> Thanks for your suggestions. I tried them all:
> - setting ToolTipText to sFileName
> - ensuring the recordset was correct (that I was not assigning a null to
> the   caption of the first button)
> - DoEvents after creating each button
> - Refresh after creating each button, on both the toolbar and the form

> Then I tried:
> - creating a dummy button in design mode, and removing all buttons added
> in   code except the dummy button each time I rebuilt the toolbar; both
> the   dummy button and the lone button added in code had no caption
> - putting a 'placeholder' button on the toolbar first
> - adding the first button twice, then removing the index-1 button after
> the   toolbar is built
> - adding the first button twice, then removing the index-2 button after
> the   toolbar is built

> None of this worked. Something is preventing the caption from appearing on
> the first button added in code, until a second button is added. Removing
> this second button makes the first button's caption disappear.



>> My first posting to a group--here goes...

>> I'm reading data from a table (in VB6) and dynamically creating a
>> toolbar, showing both an icon and a caption.

>> If the toolbar has two or more buttons on it, all looks fine.

>> If the toolbar has only one button, the caption does not appear.

>> Here's part of the code:

>> Do Until rs.EOF
>>     'get the app icon associated with this file name extension
>>     sImageKey = GetDocumentIconKey(rs("FILEPATH"))
>>     'extract file name from full path, to use as caption for button
>>     iPos = InStrRev(rs("FILEPATH"), "\")
>>     If iPos > 0 Then
>>         sFileName = Mid(rs("FILEPATH"), iPos + 1)
>>     Else
>>         sFileName = rs("FILEPATH")
>>     End If
>>     Set btnButton = Toolbar1.Buttons.Add(, , sFileName, tbrDefault,
>> sImageKey)     btnButton.ToolTipText = rs("FILEPATH")
>>     rs.MoveNext
>> Loop

>> Toolbar properties (relevent or otherwise):
>> Align - none
>> AllowCustomize - False
>> Wrappable - True
>> ShowTips - True
>> BorderStyle - none



Tue, 21 Sep 2004 06:48:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Toolbar button change caption

2. Changing toolbar button caption

3. Toolbar button caption does not support ALT keys

4. toolbar button captions

5. No more caption when changing button image in toolbar

6. toolbar control - Wordwrap in button's caption needded

7. Toolbar: Button with Bold Caption.

8. Toolbar: Button with Bold Caption.

9. Toolbar Button Caption , What FONT?

10. Toolbar: Button with Bold Caption.

11. Toolbar: Button with Bold Caption.

12. Insert toolbar button before first

 

 
Powered by phpBB® Forum Software