Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 24th, 2010, 05:34 AM
Authorized User
 
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Question Combobox binding fires after the first time it loses focus

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
__________________
Rob Carter
 
Old October 1st, 2010, 07:39 AM
Authorized User
 
Join Date: Sep 2010
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

on textChanged or keyPress, save its text in a global variable and set combobox text from this variable on its lostFocus event.hope this would help





Similar Threads
Thread Thread Starter Forum Replies Last Post
binding combobox to textbox cancertropica WinForms/Console Application Design 2 July 27th, 2009 01:21 PM
ComboBox and Get Focus JezLisle Access VBA 1 July 30th, 2007 07:35 AM
data binding a combobox ozPATT Excel VBA 1 November 16th, 2005 08:17 AM
binding combobox to sqlreader? drachx General .NET 6 October 14th, 2004 07:10 PM
ComboBox Data Binding bmains VB.NET 0 October 5th, 2004 02:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.