Solved

VB.net close Custom Task Pane

Posted on 2012-03-20
5
814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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