PDA

View Full Version : combobox با قابلیت جستجو



eshaghi
سه شنبه 23 خرداد 1385, 09:04 صبح
با عرض سلام:
من یک combo box می خواهم که searchable باشد یعنی اگر در combobox حرف b را بنویسیم تمام کلماتی را که ابتدای آن حرف b می باشد را نشان دهد واگر حرف e را بعد از b وارد کردیم آنگاه کلماتی را نشان دهد که ابتدای آنها be باشدو قابل select هم باشد. این combobox تقریبا شبیه combobox در help-index می باشد اما با این تفاوت که به پایگاه داده منعقد می شود با تشکر فراوان.

علیرضا مداح
سه شنبه 23 خرداد 1385, 10:08 صبح
سلام دوست عزیز
کامبوباکس موجود در ویژوال استادیو 2005 دارای خاصیتی بنام AutoCompleteMode میباشد که با تنظیم آن بر روی یکی از سه مقدار Suggest ، Append ، SuggestAppend میتوانید اینکار را انجام دهید.

eshaghi
سه شنبه 23 خرداد 1385, 13:03 عصر
با عرض سلام :
از راهنمایی شما متشکر هستم ولی من با ویژوال 2003 کار می کنم اگر باز هم من را راهنمایی کنطد بسیار ممنون هستم.

علیرضا مداح
سه شنبه 23 خرداد 1385, 13:31 عصر
http://www.codeproject.com/vb/net/autocomplete_combobox.asp

ashkan2005
پنج شنبه 30 آذر 1385, 08:47 صبح
با سلام
من این برنامه رو برداشتم و در فرم خودم paste کردم اما به قسمت های
Dim recName As DB.tblNameRow
lblAccountNum.Text = recName.AccountNum
lblCompanyName.Text = recName.CompanyName
error می دهه فکر می کنم این قسمت مربوط به #c باشه اگه ممکنه شکل صحیح این کد رو بنویسین با تشکر از شما عزیز:چشمک: :بوس:

ashkan2005
پنج شنبه 30 آذر 1385, 08:57 صبح
با سلام
من این کد رو برداشتم و در فرم خودم اضافه کردم فقط به قسمتهای زیر error میده


Dim recName As DB.tblNameRow
lblAccountNum.Text = recName.AccountNum
lblCompanyName.Text = recName.CompanyName
اگه میشه در مورد این سه قسمت توضیح بدین و بگین منظور از lblAccountNum,lblCompanyName, DB.tblNameRow چیه
با تشکر:بوس: :چشمک:

mostafa_leman
پنج شنبه 30 آذر 1385, 09:04 صبح
اگه از binding source یا dataview استفاده میکنی در event تغییر تکست combobox بنویس


me.bindingsource1.rowfilter = "Kala like '" & me.combobox1.text & "%'"

این خط فیلد کالا را بر اساس محتویات combobox1 فیلتر میکند

ashkan2005
پنج شنبه 30 آذر 1385, 22:40 عصر
با سلام و تشکر از شما
من مشکلم در اینه که نمی دونم این سه دستور lblAccountNum,lblCompanyName, DB.tblNameRow fvhd واسه چیه و چیکار می کنه در ضمن من اطلاعات را در قسمت item combobox نوشتم.:چشمک:

ashkan2005
پنج شنبه 30 آذر 1385, 22:44 عصر
در ضمن من این کد ها رو از اینترنت برداشتم کمی هم اصلاحش کردم کار می کنه اما یه اشکال داره ببینین میتونین رفعش

Public Shared Sub AutoComplete(ByVal combobox1 As ComboBox, _
ByVal e As System.Windows.Forms.KeyEventArgs)
' Call this from your form passing in the name
' of your combobox and the event arg:
' AutoComplete(cboState, e)
Dim iIndex As Integer = 0
Dim sActual As String
Dim sFound As String
Dim bMatchFound As Boolean
'check if the text is blank or not, if not then only proceed
If Not combobox1.Text = "" Then 'if the text is not blank then only proceed
' If backspace then remove the last character
' that was typed in and try to find
' a match. note that the selected text from the
' last character typed in to the
' end of the combo text field will also be deleted.
If e.KeyCode = Keys.Back Then
combobox1.Text = Mid(combobox1.Text, 1, Len(combobox1.Text) - 1)
End If
' Do nothing for some keys such as navigation keys...
If ((e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.End) Or _
(e.KeyCode = Keys.Enter)) Then
Return
End If
Do
combobox1.DroppedDown = True
' Store the actual text that has been typed.
sActual = combobox1.Text
' Find the first match for the typed value.
iIndex = combobox1.FindString(sActual)
' Get the text of the first match.
' if index > -1 then a match was found.
If (iIndex > -1) Then '** FOUND SECTION **
'combobox1.Text = ""
sFound = combobox1.Items(iIndex).ToString()
' Select this item from the list.
combobox1.SelectedIndex = iIndex
' Select the portion of the text that was automatically
' added so that additional typing will replace it.
'combobox1.SelectionStart = sActual.Length
'combobox1.SelectionLength = sFound.Length
bMatchFound = True
Else '** NOT FOUND SECTION **
'if there isn't a match and the text typed in is only 1 character
'or nothing then just select the first entry in the combo box.
If sActual.Length = 1 Or sActual.Length = 0 Then
combobox1.SelectedIndex = 0
combobox1.SelectionStart = 0
combobox1.SelectionLength = Len(combobox1.Text)
bMatchFound = True
Else
'if there isn't a match for the text typed in then
'remove the last character of the text typed in
'and try to find a match.
'************************** NOTE **************************
'COMMENT THE FOLLOWING THREE LINES AND UNCOMMENT
'THE (bMatchFound = True) LINE
'INCASE YOU WANT TO ALLOW TEXTS TO BE TYPED IN
' WHICH ARE NOT IN THE LIST. ELSE IF
'YOU WANT TO RESTRICT THE USER TO TYPE TEXTS WHICH ARE
'NOT IN THE LIST THEN LEAVE THE FOLLOWING THREE LINES AS IT IS
'AND COMMENT THE (bMatchFound = True) LINE.
'************************************************* **********
'/////// THREE LINES SECTION STARTS HERE ///////////
combobox1.SelectionStart = sActual.Length - 1
combobox1.SelectionLength = sActual.Length - 1
combobox1.Text = Mid(combobox1.Text, 1, Len(combobox1.Text) - 1)
'/////// THREE LINES SECTION ENDS HERE /////////////
'bMatchFound = True
End If
End If
Loop Until bMatchFound
End If
End Sub
کنین

ashkan2005
جمعه 01 دی 1385, 09:23 صبح
با سلام
دوستان عزیز اونقدر گشتم تا پیداش کردم می تونین از این تکه کد استفاده کنین.




Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Add some items to the ComboBox list.

Me.ComboBox1.Text = ""
Me.ComboBox1.Items.Add("a")
Me.ComboBox1.Items.Add("aaa")
Me.ComboBox1.Items.Add("combo")
Me.ComboBox1.Items.Add("combobox")
Me.ComboBox1.Items.Add("combobox test")
Me.ComboBox1.Items.Add("common")
Me.ComboBox1.Items.Add("common dialog")

End Sub

Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
Dim index As Integer

Dim actual As String

Dim found As String

' Do nothing for some keys such as navigation keys.

If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.End)) Then

Return

End If

' Store the actual text that has been typed.

actual = Me.ComboBox1.Text
' Find the first match for the typed value.

index = Me.ComboBox1.FindString(actual)
' Get the text of the first match.

If (index > -1) Then

found = Me.ComboBox1.Items(index).ToString()
' Select this item from the list.

Me.ComboBox1.SelectedIndex = index
' Select the portion of the text that was automatically

' added so that additional typing will replace it.

Me.ComboBox1.SelectionStart = actual.Length
Me.ComboBox1.SelectionLength = found.Length
End If

End Sub

:تشویق: