|
Logins will be handled via a windows form.
|
|
|
|
|
OK if I understand you correctly. You would have to set up a control, maybe make it invisible, that test the preference of the user to decide whether to enable the menu or not. You can do that by making the values of the menus be conditions that must be tested before being done. I personally would use an access table with the username, password, and the conditions I wanted the user to have, as far as the menus are concerned. Then I would have a label with the username entered into it after a successful logon, and then i would have a select statement that would base the preferences, or menus, for the and I would use an if statement or case statement for testing the values of the condition to determine whether to enable the menu or not.
I hope that helps you some at least.
|
|
|
|
|
williewillie wrote:
Any thoughts?
I'm not sure ccotton333 understood what you are asking, however here is another take on what you could do. Write a derived MenuItem class that inherits from MenuItem , have this perform validation against the WindowsIdentity or your own logic to specify access within the constructor, setting the enabled value appropriately. Thus, use your derived MenuItem class in place of the standard MenuItem . Does this make sense?
- Nick Parker My Blog | My Articles
|
|
|
|
|
How do I get the index of a selected item in a listbox?
Many thanks,
Glen Conaway
|
|
|
|
|
Are you talking about trying to use it somewhat like a directory structure?
|
|
|
|
|
Are you trying to use it somewhat like a directory structure?
|
|
|
|
|
Try the .SelectedIndex() property of the listbox.
Hope This Helps
Kyle
|
|
|
|
|
Works great!!!
Many Thanks,
Glen Conaway
|
|
|
|
|
Hi I am trying to create a combobox that will filter out items found in an items collection as the user enters each character. This combo box will also need to display the items within the items collection as well. I have found code that will allow me to autofill the combo box and to display the items in the collection, but have not had any luck in coding or finding code that will allow me to filter out these items. Any suggestions? Thanks.
The code found so far:
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String
Dim boxIndex As Integer, lExst As Boolean
Dim posCursor As Integer = cbo.SelectionStart
' If Cursor does not stay on the beginning of text box.
If posCursor <> 0 Then
lExst = False
'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
Return
End Select
If e.KeyCode = Keys.Enter Then
cbo.Height = 21
'RaiseEvent Submit(Me, e.Empty)
Exit Sub
End If
'Get the Typed Text and Find it in the list
sTypedText = cbo.Text
iFoundIndex = cbo.FindString(sTypedText)
'If we found the Typed Text in the list then Autocomplete
If iFoundIndex >= 0 Then
If cbo.Text <> "" Then
'cbo.DataSource().GetType.mDataViewCombo.RowFilter = cbo.DisplayMember & " LIKE '" & Me.Text & "%'"
Else
'mDataViewCombo.RowFilter = ""
End If
'Get the Item from the list (Return Type depends if Datasource was bound
' or List Created)
oFoundItem = cbo.Items(iFoundIndex)
'Use the ListControl.GetItemText to resolve the Name in case the Combo
' was Data bound
sFoundText = cbo.GetItemText(oFoundItem)
'Append then found text to the typed text to preserve case
sAppendText = sFoundText.Substring(sTypedText.Length)
cbo.Text = sTypedText & sAppendText
'Select the Appended Text
cbo.SelectionStart = sTypedText.Length
cbo.SelectionLength = sAppendText.Length
End If
End If
End Sub
|
|
|
|
|
Are you pulling the item that you fill the combo box with from an access database?
|
|
|
|
|
At the moment I am not, but I have created an arraylist to populate the data source. But after the database is completed I will be using access to populate the combo box.
|
|
|
|
|
Actually, I am new VB.Net instead of putting all the items in a collection, put the items in an array, so that, when ever u need an item from that array u can use filter function which finds the selected item and returns an zero-based array.
Thanx,
Ravi.
|
|
|
|
|
Hi, thanks for your advice, I'll try that idea out. I was just wondering how it would work when I upgrade from a manually set of data to a dataset from a data base? thanks.
|
|
|
|
|
Hi,
How about creating a custom class that inherits from ArrayList and provides a readonly property which returns a filtered list? Like this:
Public Class MyItem
Public Field1 As String
End Class
Public Class MyList
Inherits ArrayList
Public Readolny Property FilteredByField1(FilterFieldVal As String) As MyList
Get
Dim mi As MyItem
Dim rcol As New MyList
For Each mi In Me
If mi.Field1 = FilterFieldVal Then rcol.Add(mi)
Next
Return rcol
End Get
End Property
End Class
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
Hi, thanks for the advice. I was looking at using an array list to store the original data from the combobox and using that data to repopulate the combobox on the leave event. I will try this out and see how it works out. I have never used the filter functions of arraylists. Cheers
|
|
|
|
|
Hi everyone! Thanks for all of your help. I am now stuck on a key validation problem. My backspace does not delete enough of the text within a combo box for me to reset the combobox and append text etc. It will only delete this text if I hold down the backspace button. Does anyone have any suggestions? Test out the code and see if you can find anyother bugs. I also would like for the text not to completely fill the box if it is the last item until the user selects the item from the list or leaves focus on the box(would like to keep it highlighted just as if there were other items in the list). Thanks everyone!!
Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel
Public Class Form1
Inherits System.Windows.Forms.Form
Dim origData_cbo As New ArrayList
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
origData_cbo.Add("Please Select or Type an Item Name")
origData_cbo.Add("acada")
origData_cbo.Add("acura")
origData_cbo.Add("amy")
origData_cbo.Add("apple")
origData_cbo.Add("bananna")
origData_cbo.Add("orange")
origData_cbo.Add("pear")
origData_cbo.Add("person")
origData_cbo.Add("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
cbo1.DataSource = origData_cbo
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Uc_measurements2 As SingerProtype.uc_measurements
Friend WithEvents Uc_measurements3 As SingerProtype.uc_measurements
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Uc_measurements1 As SingerProtype.uc_measurements
Friend WithEvents cbo1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Uc_measurements2 = New SingerProtype.uc_measurements
Me.Uc_measurements3 = New SingerProtype.uc_measurements
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Uc_measurements1 = New SingerProtype.uc_measurements
Me.cbo1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Uc_measurements2
'
Me.Uc_measurements2.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements2.displayActual = False
Me.Uc_measurements2.Location = New System.Drawing.Point(8, 248)
Me.Uc_measurements2.Name = "Uc_measurements2"
Me.Uc_measurements2.Size = New System.Drawing.Size(392, 146)
Me.Uc_measurements2.TabIndex = 1
'
'Uc_measurements3
'
Me.Uc_measurements3.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements3.displayActual = False
Me.Uc_measurements3.Location = New System.Drawing.Point(416, 8)
Me.Uc_measurements3.Name = "Uc_measurements3"
Me.Uc_measurements3.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements3.TabIndex = 2
'
'DateTimePicker1
'
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(440, 120)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(192, 20)
Me.DateTimePicker1.TabIndex = 4
'
'Uc_measurements1
'
Me.Uc_measurements1.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements1.displayActual = False
Me.Uc_measurements1.Location = New System.Drawing.Point(16, 8)
Me.Uc_measurements1.Name = "Uc_measurements1"
Me.Uc_measurements1.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements1.TabIndex = 5
'
'cbo1
'
Me.cbo1.Location = New System.Drawing.Point(464, 240)
Me.cbo1.MaxDropDownItems = 10
Me.cbo1.Name = "cbo1"
Me.cbo1.Size = New System.Drawing.Size(296, 21)
Me.cbo1.TabIndex = 6
Me.cbo1.Text = "Please Select or Type an Item Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Location = New System.Drawing.Point(464, 224)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(304, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "AutoFill Combo Box that allows user to type extra if need be"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.ClientSize = New System.Drawing.Size(824, 454)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cbo1)
Me.Controls.Add(Me.Uc_measurements1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Uc_measurements3)
Me.Controls.Add(Me.Uc_measurements2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim uc As uc_measurements = New uc_measurements
'Uc_measurements1.showActual(False)
Uc_measurements1.showActual(True)
Uc_measurements2.showActual(False)
'[Paint gradient form]
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
'[/Paint gradient form]
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'[Declare variables]
Dim formGraphics As Graphics = e.Graphics
Dim gradientMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Dim gradientBrush As New _
LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.FromArgb(236, 233, 216), Color.FromArgb(52, 101, 75), gradientMode)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
'[/Declare variables]
End Sub
'Function used to handle the on key up event
Private Sub cbo1_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cbo1.KeyUp
AutoCompleteCombo_keyUp(sender, e)
End Sub
'Function used to display first matching item as user types letters into the combo box
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender 'takes the combo box calling the function and sets it to a local combobox
'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Back
If e.KeyValue = Keys.Back Then
append(sender, e)
End If
Exit Sub
End Select
append(sender, e)
End Sub
'Append possible text that may follow
Private Sub append(ByVal sender As Object, ByVal e As EventArgs)
Dim cbo As ComboBox = sender
Dim foundIndex As Integer = -1 'takes the users typed text and if found in a datasource, stores the index
Dim foundArrLst As New ArrayList
Dim foundText As String = ""
Dim typedText As String = "" 'takes the text typed into the combobox by the users and stores it into a local string variable
Dim appendText As String = ""
Dim posCursor As Integer = cbo.SelectionStart 'takes the position of the cursor when the function is called
typedText = cbo.Text
foundIndex = cbo.FindString(typedText)
If posCursor <> 0 Then
cbo.DroppedDown() = True
If foundIndex >= 0 Then
'Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
'Get the Item from the list (Return Type depends if Datasource was bound or List Created)
foundText = cbo.GetItemText(cbo.Items.Item(foundIndex))
'Append then found text to the typed text to preserve case
appendText = foundText.Substring(typedText.Length)
cbo.Text = typedText + appendText
reduceList(foundIndex, foundArrLst, cbo, typedText)
cbo.SelectionStart = typedText.Length
cbo.SelectionLength = appendText.Length
End If
Else
resetComboBox(sender, e)
End If
End Sub
'Reduce the List of Possibilities
Private Sub reduceList(ByVal foundIndex As Integer, ByRef foundArray As ArrayList, _
ByRef cbo As ComboBox, ByVal typedText As String)
'If we found the Typed Text in the list then Autocomplete
If foundIndex >= 0 Then
Dim item As String
For Each item In cbo.Items
' try a partial string match, looking at the first few letters of each name
' can also use If Mid(i, 1, Len(sTypedText)) = sTypedText Then
' if there's a match, stick the name in the results list
If Microsoft.VisualBasic.Left(item, typedText.Length).ToUpper = typedText.ToUpper Then
foundArray.Add(item)
End If
Next
End If
cbo.DataSource = foundArray
adjustWidth_dropDown(cbo)
cbo.DroppedDown = True
End Sub
'Calls a function to adjust the width of the combo box
Private Sub cbo1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cbo1.DropDown
adjustWidth_dropDown(cbo1)
End Sub
'Function used to handle longer text strings that don't fit in a sized combo box
Public Sub adjustWidth_dropDown(ByRef cbo As ComboBox)
Dim i As Integer
Dim tempLength As Integer = 0
Dim tempString As String = ""
Dim largestWidth As Integer = 0
Dim newWidth As Integer
Dim g As Graphics = cbo.CreateGraphics()
Dim tempFont As Font = cbo1.Font
Dim vertScrollWidth As Integer = (cbo.Items.Count > cbo.MaxDropDownItems) 'check to see if we need a scroll bar
For i = 0 To cbo.Items.Count - 1
newWidth = g.MeasureString(cbo.Items.Item(i), tempFont).Width + vertScrollWidth
If (largestWidth < newWidth) Then
largestWidth = newWidth
End If
cbo.DropDownWidth = largestWidth
Next
End Sub
'Function called when the focus leaves the combobox to reset the values in the drop down list
Private Sub cbo1_FocusLeavePrivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.Leave
resetComboBox(sender, e)
End Sub
'Function used to reset the values in the combo box drop down list to the original when a user leaves the box
Private Sub resetComboBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cbo As ComboBox = sender
Dim prevSelected As String
prevSelected = cbo.Text.ToString()
cbo.DataSource = origData_cbo
If (prevSelected <> "") Then
cbo.SelectedItem = cbo.Items.Item(cbo.FindString(prevSelected))
cbo.Text = prevSelected
End If
End Sub
Private Sub cbo1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.GotFocus
'cbo1.DroppedDown() = True
End Sub
'Not Working
Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo1.Enter
Dim wComboValue As String = "(New Item)"
If Not IsNothing(cbo1.SelectedValue) Then
wComboValue = cbo1.SelectedValue
End If
'goes in the append text to get rid of wildcards
' Remove *, ' e % from the string
'If Strings.Right(cbo.Text, 1) = "*" Or Strings.Right(cbo.Text, 1) = "'" Or Strings.Right(cbo.Text, 1) = "%" Then
'cbo.Text = cbo.Text.Substring(0, Len(cbo.Text) - 1)
'cbo.SelectionStart = cbo.Text.Length
'Exit Sub
'End If
'If cbo.Text.IndexOf("*") <> -1 Or cbo.Text.IndexOf("'") <> -1 Or cbo.Text.IndexOf("%") <> -1 Then
'cbo.Text = cbo.Text.Replace("*", "").Replace("'", "").Replace("%", "")
'End If
End Sub
End Class
|
|
|
|
|
Hi everyone, this code handles backspaces, populates the combobox..filters out the stuff that doesn't match the users input, but I am having a problem when I try to type strings that match a single word, but with more chars. I would like to be able to continue typing and displaying nothing in the combobox type thing. But, when I type the extra chars, the combobox forces me back to the start position of the combobox. Does anyone have any idea what is going on? Thank you.
Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel
Public Class Form1
Inherits System.Windows.Forms.Form
Dim origData_cbo As New ArrayList
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
origData_cbo.Add("Please Select or Type an Item Name")
origData_cbo.Add("acada")
origData_cbo.Add("acura")
origData_cbo.Add("amy")
origData_cbo.Add("apple")
origData_cbo.Add("bananna")
origData_cbo.Add("orange")
origData_cbo.Add("pear")
origData_cbo.Add("person")
origData_cbo.Add("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
cbo1.DataSource = origData_cbo
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Uc_measurements2 As SingerProtype.uc_measurements
Friend WithEvents Uc_measurements3 As SingerProtype.uc_measurements
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Uc_measurements1 As SingerProtype.uc_measurements
Friend WithEvents cbo1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Uc_measurements2 = New SingerProtype.uc_measurements
Me.Uc_measurements3 = New SingerProtype.uc_measurements
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Uc_measurements1 = New SingerProtype.uc_measurements
Me.cbo1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Uc_measurements2
'
Me.Uc_measurements2.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements2.displayActual = False
Me.Uc_measurements2.Location = New System.Drawing.Point(8, 248)
Me.Uc_measurements2.Name = "Uc_measurements2"
Me.Uc_measurements2.Size = New System.Drawing.Size(392, 146)
Me.Uc_measurements2.TabIndex = 1
'
'Uc_measurements3
'
Me.Uc_measurements3.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements3.displayActual = False
Me.Uc_measurements3.Location = New System.Drawing.Point(416, 8)
Me.Uc_measurements3.Name = "Uc_measurements3"
Me.Uc_measurements3.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements3.TabIndex = 2
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(440, 240)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(192, 20)
Me.DateTimePicker1.TabIndex = 4
'
'Uc_measurements1
'
Me.Uc_measurements1.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements1.displayActual = False
Me.Uc_measurements1.Location = New System.Drawing.Point(16, 8)
Me.Uc_measurements1.Name = "Uc_measurements1"
Me.Uc_measurements1.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements1.TabIndex = 5
'
'cbo1
'
Me.cbo1.Location = New System.Drawing.Point(408, 336)
Me.cbo1.MaxDropDownItems = 10
Me.cbo1.Name = "cbo1"
Me.cbo1.Size = New System.Drawing.Size(296, 21)
Me.cbo1.TabIndex = 6
Me.cbo1.Text = "Please Select or Type an Item Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Location = New System.Drawing.Point(408, 320)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(304, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "AutoFill Combo Box that allows user to type extra if need be"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.ClientSize = New System.Drawing.Size(824, 454)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cbo1)
Me.Controls.Add(Me.Uc_measurements1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Uc_measurements3)
Me.Controls.Add(Me.Uc_measurements2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim uc As uc_measurements = New uc_measurements
'Uc_measurements1.showActual(False)
Uc_measurements1.showActual(True)
Uc_measurements2.showActual(False)
'[Paint gradient form]
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
'[/Paint gradient form]
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'[Declare variables]
Dim formGraphics As Graphics = e.Graphics
Dim gradientMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Dim gradientBrush As New _
LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.FromArgb(236, 233, 216), Color.FromArgb(52, 101, 75), gradientMode)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
'[/Declare variables]
End Sub
'Function used to handle the on key up event
Private Sub cbo1_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cbo1.KeyUp
AutoCompleteCombo_keyUp(sender, e)
cbo1.DroppedDown() = True
End Sub
'Function used to display first matching item as user types letters into the combo box
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender 'takes the combo box calling the function and sets it to a local combobox
'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Back
If e.KeyValue = Keys.Back Then
append(sender, e, "1")
End If
Exit Sub
End Select
append(sender, e, "0")
End Sub
'Append possible text that may follow
Private Sub append(ByVal sender As Object, ByVal e As EventArgs, ByVal minus As Integer)
Dim cbo As ComboBox = sender
Dim foundIndex As Integer = -1 'takes the users typed text and if found in a datasource, stores the index
Dim foundArrLst As New ArrayList
Dim foundText As String = ""
Dim typedText As String = "" 'takes the text typed into the combobox by the users and stores it into a local string variable
Dim appendText As String = ""
Dim posCursor As Integer = cbo.SelectionStart 'takes the position of the cursor when the function is called
If (cbo.Text.Length > 0) Then
typedText = cbo.Text.Substring(0, cbo.Text.Length - minus)
End If
resetComboBox(sender, e)
foundIndex = cbo.FindString(typedText)
If posCursor <> 0 Then
If foundIndex >= 0 Then
'Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
'Get the Item from the list (Return Type depends if Datasource was bound or List Created)
foundText = cbo.GetItemText(cbo.Items.Item(foundIndex))
'Append then found text to the typed text to preserve case
appendText = foundText.Substring(typedText.Length)
cbo.Text = typedText + appendText
reduceList(foundIndex, foundArrLst, cbo, typedText)
cbo.SelectionStart = typedText.Length
cbo.SelectionLength = appendText.Length
End If
Else
resetComboBox(sender, e)
End If
End Sub
'Reduce the List of Possibilities
Private Sub reduceList(ByVal foundIndex As Integer, ByRef foundArray As ArrayList, _
ByRef cbo As ComboBox, ByVal typedText As String)
'If we found the Typed Text in the list then Autocomplete
If foundIndex >= 0 Then
Dim i As String
For Each i In cbo.Items
' try a partial string match, looking at the first few letters of each name
If Mid(i, 1, Len(typedText)) = typedText Then
' if there's a match, stick the name in the results list
foundArray.Add(i)
End If
Next
End If
'If we found the Typed Text in the list then Autocomplete
'If foundIndex >= 0 Then
'Dim item As String
'For Each item In cbo.Items
' try a partial string match, looking at the first few letters of each name
' can also use If Mid(i, 1, Len(sTypedText)) = sTypedText Then
' if there's a match, stick the name in the results list
'If Microsoft.VisualBasic.Left(item, typedText.Length).ToUpper = typedText.ToUpper Then
'foundArray.Add(item)
'End If
'Next
'End If
cbo.DataSource = foundArray
adjustWidth_dropDown(cbo)
cbo.DroppedDown = True
End Sub
'Calls a function to adjust the width of the combo box
Private Sub cbo1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cbo1.DropDown
adjustWidth_dropDown(cbo1)
End Sub
'Function called when the focus leaves the combobox to reset the values in the drop down list
Private Sub cbo1_FocusLeavePrivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.Leave
resetComboBox(sender, e)
End Sub
'Function used to reset the values in the combo box drop down list to the original when a user leaves the box
Private Sub resetComboBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cbo As ComboBox = sender
Dim prevSelected As String
prevSelected = cbo.Text.ToString()
cbo.DataSource = origData_cbo
If cbo.FindString(prevSelected) >= 0 Then
cbo.SelectedItem = cbo.Items.Item(cbo.FindString(prevSelected))
cbo.Text = prevSelected
End If
End Sub
'Function used to handle longer text strings that don't fit in a sized combo box
Public Sub adjustWidth_dropDown(ByRef cbo As ComboBox)
Dim i As Integer
Dim tempLength As Integer = 0
Dim tempString As String = ""
Dim largestWidth As Integer = 0
Dim newWidth As Integer
Dim g As Graphics = cbo.CreateGraphics()
Dim tempFont As Font = cbo1.Font
Dim vertScrollWidth As Integer = (cbo.Items.Count > cbo.MaxDropDownItems) 'check to see if we need a scroll bar
For i = 0 To cbo.Items.Count - 1
newWidth = g.MeasureString(cbo.Items.Item(i), tempFont).Width + vertScrollWidth
If (largestWidth < newWidth) Then
largestWidth = newWidth
End If
cbo.DropDownWidth = largestWidth
Next
End Sub
Private Sub cbo1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.GotFocus
cbo1.DroppedDown() = True
End Sub
'Not Working
Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo1.Enter
Dim wComboValue As String = "(New Item)"
If Not IsNothing(cbo1.SelectedValue) Then
wComboValue = cbo1.SelectedValue
End If
'goes in the append text to get rid of wildcards
' Remove *, ' e % from the string
'If Strings.Right(cbo.Text, 1) = "*" Or Strings.Right(cbo.Text, 1) = "'" Or Strings.Right(cbo.Text, 1) = "%" Then
'cbo.Text = cbo.Text.Substring(0, Len(cbo.Text) - 1)
'cbo.SelectionStart = cbo.Text.Length
'Exit Sub
'End If
'If cbo.Text.IndexOf("*") <> -1 Or cbo.Text.IndexOf("'") <> -1 Or cbo.Text.IndexOf("%") <> -1 Then
'cbo.Text = cbo.Text.Replace("*", "").Replace("'", "").Replace("%", "")
'End If
End Sub
End Class
|
|
|
|
|
The idea behined this is to create a report writer, we have found or did got solution on Crystal report when we view the report as may times the different window will shown
which we could control from in send of VB Program...
that is why we started write a new program were we can customise the report according our level. as RichtexBox gives the fecility to change fonts etc .. we got the solution to add the Image but we can't control the Image as in terms of size and postion
Please advice
|
|
|
|
|
You COULD use the RichTextBox control, but it doesn't offer the flexibility of EXACT placement and scaling control of images that you want. Your best bet is either Crystal Reports, or custom writing your own code for drawing each page exactly the way you want it using GDI+, not a RichTextBox.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The idea behined this is to create a report writer, we have found or did got solution on Crystal report when we view the report as may times the different window will shown
which we could control from in send of VB Program...
that is why we started write a new program were we can customise the report according our level. as RichtexBox gives the fecility to change fonts etc .. we got the solution to add the Image but we can't control the Image as in terms of size and postion
Please advice
|
|
|
|
|
Hi,
I am trying to get my new mail application for a schoole project to recognize URLs dragged onto it as the actual files the URLs are pointing to, .i.e, if I drag a URL onto it, it should attach the file, not just give the path to the file. At the moment, I am just managing to get it to drop the text of the URL. Any advice or pointers to useful code will be much appreciated.
Thanks
|
|
|
|
|
Wow, not easy. You app has to, when a URL is dropped on it, handle the drag and drop code the same way you are now. But when you get the URL text that points to the file, you must download the file and then your code mush attach the file that was downloaded.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi everybody
is there any way to keep an exe file into vb 6.0 so that when ever i close the form the application should also close (i.e the exe file should act as a child form in main form)
thank you all
|
|
|
|
|
This doesn't make any sense at all...
Are you asking if it is possible to run an external application and make its windows child windows of your application? Where the windows are actually MDIChildren in your application?
If this is what your asking, then no it's not. The application will put up it's own windows that are not managable from outside that application.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello
the problem i'm having is that i cant get the value i wanted from a .txt file
value in .txt file
123.445
value after call .readline
123445
the value in the .txt is a double value but when i call it to the application it become integer.
did i type the wrong coding?
the declaration and coding is as below
Dim num1 As Double
Dim sr As IO.StreamReader = IO.File.OpenText("info.txt")
Do While (sr.Peek <> -1)
num1 = CDbl(sr.ReadLine)
Loop
Text1.Text = num1
i even try almost everything i know
but the output is still 123445 and not 123.445
please help me
thank you
Gary the amatuer
|
|
|
|
|