RobCarter
New member
Hi
I have an issue with comboboxes whereby when a winform is loaded for the first time and my box is populated, I can select an item from it. If I click away from the combobox onto whitespace or another form control, it looks like the combobox data is repopulated. This only happens the first time focus is lost from the combobox.
It is bound to a datasource with a new row at index 0 called -- All --
This is the form code:
and this is the form that builds the combobox:
I am using the selectionchangecommitted event to filter a listview by the item in the combobox. I did try setting a class level variable but I may have been missing the concept as it was refreshed every time the combobox was.
Thankyou to anyone who can provide assistance.
Rob
I have an issue with comboboxes whereby when a winform is loaded for the first time and my box is populated, I can select an item from it. If I click away from the combobox onto whitespace or another form control, it looks like the combobox data is repopulated. This only happens the first time focus is lost from the combobox.
It is bound to a datasource with a new row at index 0 called -- All --
This is the form code:
VB.NET:
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
Imports CHIT_Printing.ROHClinics.Clinics
Public Class frmChitPrinter
Public varLoad As Integer = 0
Public varClino As String = ""
Protected Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindDrop(Me.ddlClinic)
GetPrinters(Me.ddlPrinter)
BindGrid(getRBLVal())
varLoad = 1
End Sub
Private Sub BindGrid(ByVal sPath As String)
Dim objConn As SqlConnection = New SqlConnection("Data Source=DSRCE;Database=DBASE;UID=USER;PWD=PASS")
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=DSRCE;Database=DBASE;UID=USER;PWD=PASS")
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 ddlClinic_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlClinic.SelectionChangeCommitted
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
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 = "verifiedpath\NewTrackerChit.xls"
xlWorksheet = "sheet1"
sActive = "Y"
sAdhoc = "Y"
Case Else
xlWorkbook = "verifiedpath\NewClosedTrackerChit.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
and this is the form that builds the combobox:
VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Security
Namespace ROHClinics
Public Class Clinics
Shared Sub BindDrop(ByRef cbo As ComboBox)
Dim objConn As SqlConnection = New SqlConnection("Data Source=DSRCE;Database=DBASE;UID=USER;PWD=PASS")
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 cbo
.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
End Class
End Namespace
I am using the selectionchangecommitted event to filter a listview by the item in the combobox. I did try setting a class level variable but I may have been missing the concept as it was refreshed every time the combobox was.
Thankyou to anyone who can provide assistance.
Rob