Solved

VB.net close Custom Task Pane

Posted on 2012-03-20
5
811 Views
Last Modified: 2012-06-27
Hi

I am using the code below to load a UserControl called "TpSqlEdit" as a Custom Task Pane at the bottom of the screen in Excel. What code would I use to make the custom task pane go away (become invisible) using a button click event on the task pane itself:

Public Class TpSQLEdit

    Private Sub buttonCloseTp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCloseTp.Click
         '######### CODE NEEDED HERE ############
    End Sub
End Class

Public Class ThisAddIn


    Private _tpSqlEdit As TpSQLEdit
    Public TpSqlEditCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane


    Private Sub ThisAddIn_Startup() Handles Me.Startup
        'Fire the Custom TaskPane
        AddTpSqlEdit()
    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    'Create the Custom TaskPane and Dock Bottom
    'You must Add your Control here
    Private Sub AddTpSqlEdit()
        _tpSqlEdit = New TpSqlEdit()
        TpSqlEditCustomTaskPane = CustomTaskPanes.Add(_tpSqlEdit, "SQL Editor")
        TpSqlEditCustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionBottom
        'Show TaskPane
        TpSqlEditCustomTaskPane.Visible = True
    End Sub


End Class
0
Comment
Question by:murbro
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37741404
Try

 CustomTaskPanes.Remove(_tpSqlEdit)
0
 

Author Comment

by:murbro
ID: 37741466
Hi

I get that both  "CustomTaskPanes"  and "_tpSqlEdit" are not declared
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37743982
Where are you calling that code? _tpSqlEdit  is class level so should be accessible.
0
 

Author Comment

by:murbro
ID: 37744265
This is behind TpSQLEdit.vb file (UserControl), and I call the code at the line marked with 'XXXXX

Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel


Public Class TpSQLEdit

    Private Sub buttonGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonGetData.Click
        Call PopulateFromSql()
    End Sub

    Private Sub PopulateFromSql()
        Try
            'Dim strCN As String = "server=196.220.43.247,1444;uid=murbro73;pwd=chestnut3;database=test"
            ' DataTable Construction with Adapter and Connection
            Dim conn = New SqlConnection(textBoxCS.Text)
            Dim strSql = richTextBoxSQLEdit.Text
            conn.Open()
            Dim da = New SqlDataAdapter(strSql, conn)
            Dim dt = New System.Data.DataTable()
            da.Fill(dt)

            ' Define the active Worksheet
            Dim sht = TryCast(Globals.ThisAddIn.Application.ActiveSheet, Worksheet)

            Dim rowCount = 0
            progressBarGetData.Minimum = 1
            progressBarGetData.Maximum = dt.Rows.Count

            ' Loop thrue the Datatable and add it to Excel
            For Each dr As DataRow In dt.Rows
                rowCount += 1
                For i As Integer = 1 To dt.Columns.Count
                    ' Add the header the first time through
                    If rowCount = 2 Then
                        ' Add the Columns using the foreach i++ to get the cell references
                        If sht IsNot Nothing Then
                            sht.Cells(1, i) = dt.Columns(i - 1).ColumnName
                        End If
                    End If
                    ' Increment value in the Progress Bar
                    progressBarGetData.Value = rowCount
                    ' Add the Columns using the foreach i++ to get the cell references
                    If sht IsNot Nothing Then
                        sht.Cells(rowCount, i) = dr(i - 1).ToString()
                    End If
                    ' Refresh the Progress Bar
                    progressBarGetData.Refresh()
                Next
            Next
        Catch ex As Exception
            Throw New Exception(ex.ToString())
        End Try

    End Sub

    Private Sub buttonCloseTp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCloseTp.Click
        CustomTaskPanes.Remove(_tpSqlEdit) 'XXXXXXXX
    End Sub

    Private Sub label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles label1.Click

    End Sub

    Public Sub Load_DataGridView()


        Dim ColumnLetters As String
        Dim Ltr As Object
        'Dim Target As Object
        'Dim cboTemp As Object
        Dim I As Integer

        For I = 1 To 10

            'Ltr = Split(Range("B5").Address(True, False), "$")
            'Col = Ltr(0)

            Ltr = Split(Globals.ThisAddIn.Application.Range(Globals.ThisAddIn.Application.Cells(1, I), Globals.ThisAddIn.Application.Cells(1, I)).Address(True, False), "$")
            ColumnLetters = Ltr(0)

            'Add ComboBoxes
            'Target = Globals.ThisAddIn.Application.Range(Globals.ThisAddIn.Application.Cells(1, I), Globals.ThisAddIn.Application.Cells(1, I))

            'cboTemp = Globals.ThisAddIn.Application.ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1")

            'cboTemp.Name = ColumnLetters


            'With cboTemp

            '.Visible = True
            '.Left = Target.Left
            '.Top = Target.Top
            '.Width = Target.Width + 3
            '.Height = Target.Height + 5

            'End With



        Next I

    End Sub


End Class
0
 

Author Closing Comment

by:murbro
ID: 37763056
thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question