Hi all
I hope you can help. I have looked on so many internet forums and the solution must be so simple.
I have a combo box on a winform that contains data that filters the information in a listview. When the combobox loses focus, the selection returns to the top of the list and changes the value of the combobox, re-filtering the listview.
Here's the code for the form:
Code:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Security
Imports CHIT_Printing.ROHDoc.CreateDoc
Imports System.Drawing.Printing
Imports Microsoft.VisualBasic.Strings
Imports Microsoft.VisualBasic.DateAndTime
Imports CHIT_Printing.ROHPrinters.Printers
Imports CHIT_Printing.ListViewData
Imports System.IO
Imports System.Diagnostics.Process
Imports System.Windows.Forms
Imports Microsoft.Office.Interop
Imports System.Reflection.Assembly
Public Class Form1
Protected Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If varLoad = 0 Then
BindDrop()
GetPrinters(Me.ddlPrinter)
BindGrid(getRBLVal())
End If
varLoad = 1
End Sub
Private Sub BindGrid(ByVal sPath As String)
Dim objConn As SqlConnection = New SqlConnection("Data Source=SOURCE;Database=DB;UID=;PWD=")
FillListView(lstSummary, GetCategories(sPath))
objConn.Close()
End Sub
Public Function GetCategories(ByVal sPath As String) As SqlDataReader
Dim objConn As SqlConnection = New SqlConnection("Data Source=SOURCE;Database=DB;UID=;PWD=")
Dim objComm As SqlCommand
Dim objDR As SqlDataReader
Dim sDate As String = Microsoft.VisualBasic.Strings.Right(ctlCalendar1.Text, 4) & Microsoft.VisualBasic.Strings.Right("000" & Month(CDate(ctlCalendar1.Text)), 2) & Microsoft.VisualBasic.Strings.Right("000" & Microsoft.VisualBasic.DateAndTime.Day(CDate(ctlCalendar1.Text)), 2)
Dim sClino As String = txtClinicCode.Text
objConn.Open()
If sPath = "N" Then
objComm = New SqlCommand("spGetChitForADHOCClinicClosedPathway_CHITPRINT", objConn)
Else
objComm = New SqlCommand("spGetChitForADHOCClinicOpenPathway_CHITPRINT", objConn)
End If
With objComm
.Parameters.AddWithValue("@SchedDate", sDate)
.Parameters.AddWithValue("@SpontRefno", varClino)
.CommandType = CommandType.StoredProcedure
.CommandTimeout = 0
End With
objDR = objComm.ExecuteReader()
Return objDR
End Function
Protected Sub BindDrop()
Dim objConn As SqlConnection = New SqlConnection("Data Source=SOURCE;Database=DB;UID=;PWD=")
Dim myDA As New SqlDataAdapter
Dim myDS As New DataSet
'If varLoad = 0 Then
objConn.Open()
Try
Dim SqlCommand As New SqlCommand("spGetServicePoints", objConn)
SqlCommand.CommandType = CommandType.StoredProcedure
myDA.SelectCommand = SqlCommand
myDA.Fill(myDS)
Dim myDR As DataRow = myDS.Tables(0).NewRow
myDR(0) = ""
myDR(1) = "-- All --"
myDS.Tables(0).Rows.InsertAt(myDR, 0)
With ddlClinic
.DataBindings.Add("DataSource", myDS, myDS.Tables(0).TableName)
.DisplayMember = myDS.Tables(0).Columns(1).ToString
.ValueMember = myDS.Tables(0).Columns(0).ToString
.DataSource = myDS.Tables(0)
End With
Catch ex As Exception
Finally
objConn.Close()
End Try
'End If
End Sub
Protected Sub ddlClinic_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlClinic.SelectedValueChanged
'If varLoad = 0 Then
' Dim val As String = ""
' For Each c As RadioButton In Me.RadioButtonList2.Controls
' If c.Checked = True Then
' Select Case c.Name
' Case "rbgPathway"
' val = "Y"
' Case "rbgNoPath"
' val = "N"
' Case Else
' MsgBox("whoops")
' End Select
' End If
' Exit For
' Next
TextBox1.Text = ddlClinic.SelectedValue.ToString
varClino = TextBox1.Text
BindGrid(getRBLVal())
'End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim val As String = ""
'For Each c As RadioButton In Me.RadioButtonList2.Controls
' If c.Checked = True Then
' MsgBox(c.Name)
' Select Case c.Name
' Case "rbgPathway"
' val = "Y"
' Case "rbgNoPath"
' val = "N"
' Case Else
' MsgBox("whoops")
' End Select
' End If
'Next
'lblRBLVAL.Text += RadioButtonList2.Text
BindGrid(getRBLVal())
End Sub
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim GridItem As ListViewItem
Dim sDoc As String = ""
Dim sActive As String = ""
Dim sAdhoc As String = ""
Dim sDirDoc As String = ""
Dim xlWorkbook As String = ""
Dim xlWorksheet As String = ""
Dim i As Integer
Dim s As Integer
Dim Proc As New System.Diagnostics.Process
Dim val As String = ""
For Each GridItem In lstSummary.Items
i = 1
If GridItem.Selected = True Then
s = 1
Select Case val
Case "N"
xlWorkbook = "verifiedworkbooklocation.xls"
xlWorksheet = "sheet1"
sActive = "Y"
sAdhoc = "Y"
Case Else
xlWorkbook = "verifiedworkbooklocation.xls"
xlWorksheet = "sheet1"
sActive = "N"
sAdhoc = "Y"
End Select
MergeDoc(sDoc, _
ddlPrinter.SelectedItem.ToString, _
lstSummary.SelectedItems(0).SubItems(7).Text, _
Format(CDate(lstSummary.SelectedItems(0).SubItems(6).Text), "yyyyMMdd"), _
lstSummary.SelectedItems(0).SubItems(4).Text, _
sActive, _
sAdhoc, _
lstSummary.SelectedItems(0).SubItems(0).Text)
s += 1
End If
i += 1
Next GridItem
End Sub
Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelect.Click
Dim GridItem As ListViewItem
For Each GridItem In lstSummary.Items
GridItem.Selected = True
Next GridItem
lstSummary.Focus()
End Sub
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
Dim GridItem As ListViewItem
For Each GridItem In lstSummary.Items
GridItem.Selected = False
Next GridItem
lstSummary.Focus()
End Sub
Protected Sub selectedChits(ByVal sender As Object, ByVal e As ListViewItemSelectionChangedEventArgs) Handles lstSummary.ItemSelectionChanged
Dim i As Integer
Dim s As Integer
Dim GridItem As ListViewItem
lblTotalChits.Text = "Total No of CHITs:"
Me.lblSelectedChits.Text = "Selected CHITs for printing:"
For Each GridItem In lstSummary.Items
i += 1
If GridItem.Selected = True Then
s += 1
End If
Next GridItem
Me.lblSelectedChits.Text += s.ToString
Me.lblTotalChits.Text += i.ToString
End Sub
Protected Sub ddlclinic_lostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlClinic.LostFocus
txtClinicCode.Text = ddlClinic.SelectedValue.ToString
Me.txtClinicName.Text = ddlClinic.SelectedText.ToString
End Sub
Function getRBLVal() As String
Dim val As String = ""
For Each c As RadioButton In RadioButtonList2.Controls
If c.Checked = True Then
Select Case c.Name
Case "rbgPathway"
val = "Y"
Case "rbgNoPath"
val = "N"
Case Else
MsgBox("whoops")
End Select
End If
Exit For
Next
getRBLVal = val
End Function
End Class
Can someone please point me in the right direction to fix this, because it's driving me barmy!
Many thanks for reading
Rob