Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. CheckListBox binding to an Excel Spreadsheet

CheckListBox binding to an Excel Spreadsheet

Scheduled Pinned Locked Moved Visual Basic
wpfwcfhelpquestion
8 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tazy
    wrote on last edited by
    #1

    Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()

    C A 2 Replies Last reply
    0
    • T Tazy

      Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Tazy wrote:

      I am new to programming

      Then why are you working on something this complex ? No-one is paying for your 'new to programming' code, are they ? If so, shame on you. If you're learning, choose something simpler to start with. You're just guessing here, and you'd do better to take a methodical approach to learning.

      Tazy wrote:

      'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This

      Well, a MsgBox is the wrong approach to take with ASP.NET anyhow, that will kill your server in a hurry. However, I assume this is debug code. Try instead to set a breakpoint. You'll find that the item is actually a DataRow, so you need to do Items(0)("SystemName"), or whatever. In futurem don't say 'this didn't work', say 'this threw this excpetion', or 'this gave me a different result to what i hoped for, as follows... ', or 'this gave me the following compiler error. And, for the love of all that is holy, buy a book and refer to it before asking questions. That's another step towards learning, towards actually becoming a programmer. People who take those sort of steps, are the sort of people we most like to help, because it doesn't feel like smashing your head against a wall.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      T 1 Reply Last reply
      0
      • T Tazy

        Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        One error I spotted

        Tazy wrote:

        CheckedListBox1.DisplayMember = ds.Tables(0).TableName

        should be something like CheckedListBox1.DisplayMember = "SystemName" (or whichever column you want to display) Hope this helps

        Bob Ashfield Consultants Ltd

        T 1 Reply Last reply
        0
        • A Ashfield

          One error I spotted

          Tazy wrote:

          CheckedListBox1.DisplayMember = ds.Tables(0).TableName

          should be something like CheckedListBox1.DisplayMember = "SystemName" (or whichever column you want to display) Hope this helps

          Bob Ashfield Consultants Ltd

          T Offline
          T Offline
          Tazy
          wrote on last edited by
          #4

          Good Morning Bob, And once again Thx for your assistance. I tried your response will was given only: "System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?

          C A 2 Replies Last reply
          0
          • T Tazy

            Good Morning Bob, And once again Thx for your assistance. I tried your response will was given only: "System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            This is further proof that my answer is correct. Did you try what I suggested ?

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            1 Reply Last reply
            0
            • C Christian Graus

              Tazy wrote:

              I am new to programming

              Then why are you working on something this complex ? No-one is paying for your 'new to programming' code, are they ? If so, shame on you. If you're learning, choose something simpler to start with. You're just guessing here, and you'd do better to take a methodical approach to learning.

              Tazy wrote:

              'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This

              Well, a MsgBox is the wrong approach to take with ASP.NET anyhow, that will kill your server in a hurry. However, I assume this is debug code. Try instead to set a breakpoint. You'll find that the item is actually a DataRow, so you need to do Items(0)("SystemName"), or whatever. In futurem don't say 'this didn't work', say 'this threw this excpetion', or 'this gave me a different result to what i hoped for, as follows... ', or 'this gave me the following compiler error. And, for the love of all that is holy, buy a book and refer to it before asking questions. That's another step towards learning, towards actually becoming a programmer. People who take those sort of steps, are the sort of people we most like to help, because it doesn't feel like smashing your head against a wall.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              T Offline
              T Offline
              Tazy
              wrote on last edited by
              #6

              No I'm new on the job and just grad. from school and this is part of a project my boss has asked me to take over. I thought this would be easier then this and would make me look good, but school has prepared me enough for this type of project. But I also don't like to give up, so I keep trying. I don't want him to think that he hired the wrong person for the job.

              C 1 Reply Last reply
              0
              • T Tazy

                No I'm new on the job and just grad. from school and this is part of a project my boss has asked me to take over. I thought this would be easier then this and would make me look good, but school has prepared me enough for this type of project. But I also don't like to give up, so I keep trying. I don't want him to think that he hired the wrong person for the job.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                OK - well, like I said, when you get an item from the items collection, it's a datarow, so you need to look up the data in the column you want to view from there. That's what the control does with the displaymember property.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                1 Reply Last reply
                0
                • T Tazy

                  Good Morning Bob, And once again Thx for your assistance. I tried your response will was given only: "System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?

                  A Offline
                  A Offline
                  Ashfield
                  wrote on last edited by
                  #8

                  Sorry, didn't read the code fully. :-O Christian's reply is correct.

                  Bob Ashfield Consultants Ltd

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups