VB + datasource + checkedlistbox = me hitting the wall
Let me start off by asking you to forgive my newbness.
Here's what I'm attempting:
The user browses for and opens a dbf file.
The user is presented with a checkedlistbox which shows the column headers.
The user then selects the columns they wish to run a report on. ex. total # of cells not empty, longest cell length, etc.
I'm to the point of populating the checkedlistbox with all of the columns shown but I'm unsure if the users selections are actually linked to my data and if they are how I go about isolating said selections for the reports.
I have a feeling that my approach to populating the checkedlistbox is not the proper way for what I'm trying to accomplish.
Any and all help would be greatly appreciated.
Here is the code
Code:
Public Sub btnGetFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFile.Click
Dim fileLookUp As New OpenFileDialog
fileLookUp.Title = "Open File"
fileLookUp.Filter = "DBF Files (*.dbf)|*.dbf|All Files (*.*)|*.*"
If fileLookUp.ShowDialog() = DialogResult.OK Then
Me.txtFile.Text = fileLookUp.FileName
mFileName = System.IO.Path.GetFileName(Me.txtFile.Text)
mFolder = System.IO.Path.GetDirectoryName(Me.txtFile.Text)
End If
End Sub
Public Sub btnReadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadData.Click
Dim conn As New OleDb.OleDbConnection
conn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=" & mFolder & "\;Extended Properties='text;HDR=Yes'"
conn.Open()
Dim strFOX As String = "SELECT * FROM " & mFileName & ";"
Dim da As New OleDb.OleDbDataAdapter(strFOX, conn)
da.Fill(ds, " & mFolder & ")
Dim iCounter As Integer
Dim Var As Integer
iCounter = dg.ColumnCount
Do While iCounter <> 0
iCounter = iCounter - 1
Me.CheckedListBox1.Items.Add(ds.Tables(0).Rows(0).Table.Columns(0 + Var).ToString(), False)
Me.CheckedListBox1.Name = "col" & ds.Tables(0).Rows(0).Table.Columns(0 + Var).ToString()
Me.Controls.Add(CheckedListBox1)
Var = Var + 1
Loop
End Sub