Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Re-Focus() Problem - Urgent Please Help !!!

Status
Not open for further replies.

Mahey

Programmer
Dec 24, 2008
52
SA
Helo,

A Listview is added with combobox. My problem is it's not refocusing the listview for the second click [re-click].

Anyone can help me?

The following will describe class codings
---------------------------------------------
Public Class Combu_lstview
Inherits ComboBox

'Dim combu_lstview As String

Private treeViewHost As ToolStripControlHost
Private Shadows dropdown As ToolStripDropDown

Public WithEvents mylistview As New System.Windows.Forms.ListView

Public Sub New()
mylistview.BorderStyle = BorderStyle.None
mylistview.View = View.Details
mylistview.HeaderStyle = ColumnHeaderStyle.Nonclickable
mylistview.Height = 200
mylistview.Width = 420
mylistview.GridLines = True
treeViewHost = New ToolStripControlHost(mylistview)
dropdown = New ToolStripDropDown()
dropdown.Items.Add(treeViewHost)
End Sub

Private Const WM_USER As Integer = &H400
Private Const WM_REFLECT As Integer = WM_USER + &H1C00
Private Const WM_COMMAND As Integer = &H111
Private Const CBN_DROPDOWN As Integer = 7

Private Sub ShowDropDown()
If Not (dropdown Is Nothing) Then
treeViewHost.Width = 500
treeViewHost.Height = 300
dropdown.Show(Me, 0, Me.Height)
dropdown.Focus()

End If
End Sub

Public Shared Function HIWORD(ByVal n As Integer) As Integer
Return (n >> 16) And &HFFFF
End Function

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_REFLECT + WM_COMMAND Then
If HIWORD(CType(m.WParam, Integer)) = CBN_DROPDOWN Then
ShowDropDown()
Return
End If
End If
MyBase.WndProc(m)
End Sub

End Class

-----------------------------------------
The following will describe Form-codings
------------------------------------------

Imports System.Data.SqlClient
Imports System.Drawing.Drawing2D

Public Class Form1

Public WithEvents treecombo As New Combu_lstview

Dim con As New SqlConnection("Data Source=1.1.1.2; initial Catalog=Emp_Management; User Id=sa; Password=123456789")
Dim cmd1 As New SqlCommand("Select * from emp_professions", con)
Dim dr1 As SqlDataReader


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

treecombo.mylistview.Columns.Add("Professions in English", 200, HorizontalAlignment.Left)
treecombo.mylistview.Columns.Add("Professions in Arabic", 200, HorizontalAlignment.Left)
treecombo.mylistview.BackColor = Me.ComboBox1.BackColor
treecombo.mylistview.ForeColor = Me.ComboBox1.ForeColor
treecombo.mylistview.Font = New System.Drawing.Font("Times New Roman", 8.0, FontStyle.Italic)
treecombo.mylistview.HoverSelection = True
treecombo.mylistview.FullRowSelect = True
treecombo.Width = ComboBox1.Width
cmd1.Connection.Open()
dr1 = cmd1.ExecuteReader
While dr1.Read
treecombo.mylistview.Items.Add(dr1(0))
treecombo.mylistview.Items(treecombo.mylistview.Items.Count - 1).SubItems.Add(dr1(1))
End While

cmd1.Connection.Close()
treecombo.mylistview.Visible = True
ComboBox1.Controls.Add(treecombo)
AddHandler treecombo.mylistview.MouseClick, AddressOf DynCtrl_Event
AddHandler treecombo.MouseClick, AddressOf DymnCtrl_Event

End Sub

Private Sub DynCtrl_Event(ByVal sender As System.Object, ByVal e As System.EventArgs)

ComboBox1.Text = treecombo.mylistview.SelectedItems(0).Text
treecombo.mylistview.Visible = False

End Sub


Private Sub DymnCtrl_Event(ByVal sender As System.Object, ByVal e As System.EventArgs)

treecombo.mylistview.Visible = True
treecombo.mylistview.Focus()
ComboBox1.Text = treecombo.mylistview.SelectedItems(0).Text

End Sub

End Class


by
MAHEY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top