PDA

View Full Version : فیلترینگ در combobox



NaserNet
پنج شنبه 14 اسفند 1382, 06:00 صبح
من چند روز پیش پروژه از پایگاه داده ام رو تحویل دادم استادم حال کرد.
اما چند تا ایراد گرفت که یکی از ان این بود که در پروژه ثبت نام و انتخاب واحد دانشگاه نام دانشجو نباید Textbox
باشد و باید از Combobox استفاده کنند
بدین صورت که در ابتدا مثلا 30 دانشجوی نخست را نشان دهد و ان را فیلتر کند بهد با تایپ یک حرف 30 دانشجوی که نام انها با ان حرف
شروع می شود فیلتر کند و جایگزین کند و خلاصه با تایپ هر حرف به هدف نزدیکتر شود

این کار شدنی است (نگید که نمیشه ) چون استاد مادر پروژه vb6 این کارو کرده ولی کد ان در اختیار من نیست .

حالا شما کمک کنید و این مشکل را حل کنید.
ممنون

h_rezaei
پنج شنبه 14 اسفند 1382, 09:27 صبح
کار ساده ای فقط تو VB6 میخوای یا VB.NET ؟

NaserNet
یک شنبه 17 اسفند 1382, 07:15 صبح
vb.net

ببین اگر کدش زیاده mail بدم فایل شو میل کن

ممنون

gh_fereydonpoor
پنج شنبه 21 اسفند 1382, 21:31 عصر
سلام
میتونی از Event ، TextChange استفاده کنی و هرباز که اتفاق می افته 30 تا رکورد بخونی و Bind کنی شون به Comboboxe

sh
پنج شنبه 21 اسفند 1382, 21:56 عصر
سلام


Private Sub cboName_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
Handles cboName.Leave
Dim recRowView As DataRowView
Dim recName As DB.tblNameRow

AutoCompleteCombo_Leave(cboName)

'OPTIONAL: Now you can do some extra handling if you want

'Get the Selected Record from my Data Bound Combo (Return Type is DataRowView)
recRowView = cboName.SelectedItem
If recRowView Is Nothing Then Exit Sub

'Display the Name Info (Row Type comes from my bound Dataset)
recName = recRowView.Row
lblAccountNum.Text = recName.AccountNum
lblCompanyName.Text = recName.CompanyName

End Sub

Private Sub cboName_KeyUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboName.KeyUp

AutoCompleteCombo_KeyUp(cboName, e)

End Sub

Here are the Generic Functions for handling the events:
Public Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

'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

'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

'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 Sub


Public Sub AutoCompleteCombo_Leave(ByVal cbo As ComboBox)
Dim iFoundIndex As Integer

iFoundIndex = cbo.FindStringExact(cbo.Text)

cbo.SelectedIndex = iFoundIndex

End Sub

NaserNet
دوشنبه 25 اسفند 1382, 06:30 صبح
سلام
یا من منظورم را درست نرساندم یا شما اشتباه برداشت کرده اید
من می خوام مثلا اگر حرف c
رو فشار داد کامبو باکس باز شده و ایتم هایی که با حرف c
شروع می شوند نشان داده شود تا از این لیست فیلتر شده یکی را انتخاب کند

ولی باز هم ممنون زحمت کشیدید کد رو در اختیار من قرار دادید
با تشکر

sh
دوشنبه 25 اسفند 1382, 15:41 عصر
ببین اینا بدرد میخورن

http://rr.exhedra.com/Upload_PSC/ftp/Automatic_16849712182003.zip
http://rr.exhedra.com/upload_PSC/ftp/Auto_Compl728584172002.zip

یا


Module Module1
Public Sub AutoComplete(ByVal cbo 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
Dim sActual As String
Dim sFound As String
Dim bMatchFound As Boolean
'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
cbo.Text = Mid(cbo.Text, 1, Len(cbo.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)) Then
Return
End If
Do
' Store the actual text that has been typed.
sActual = cbo.Text
' Find the first match for the typed value.
iIndex = cbo.FindString(sActual)
' Get the text of the first match.
'if index > -1 then a match was found.
If (iIndex > -1) Then
sFound = cbo.Items(iIndex).ToString()
' Select this item from the list.
cbo.SelectedIndex = iIndex
' Select the portion of the text that was automatically
' added so that additional typing will replace it.
cbo.SelectionStart = sActual.Length
cbo.SelectionLength = sFound.Length
bMatchFound = True
Else
'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
cbo.SelectedIndex = 0
cbo.SelectionStart = 0
cbo.SelectionLength = Len(cbo.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.
cbo.SelectionStart = sActual.Length - 1
cbo.SelectionLength = sActual.Length - 1
cbo.Text = Mid(cbo.Text, 1, Len(cbo.Text) - 1)
End If
End If
Loop Until bMatchFound
End Sub
End Module

NaserNet
پنج شنبه 28 اسفند 1382, 07:18 صبح
سلام
ممنون
بعدا اونا رو نگاه می کنم و تست می کنم
عید شما مبارک sh
سال خوبی داشته باشید
پیروز و سربلند باشید
:wink: :wink:

soroosh_i58
دوشنبه 28 آذر 1384, 17:57 عصر
سلام...
من با استفاده از راهنمایی شما یک combo box autocomplete درست کردم
توی این combo نامهای خانوادگی هستند....حالا فرض کنید چند نفر به نام "امیری" وجود داشته باشند...من هر کدوم از اونهارو که انتخاب میکنم وقتی focouse از روی اون combo برداشته میشه مقدار combo به اولین امیری تغییر پیدا میکنه...به عبارت دیگه وقتی توی این کامبو مقدار تکراری وجود داشته باشه فقط اولین عنصر اون مقدار انتخاب میشه...باید چیکار کنم؟

علی کلاهدوزان
دوشنبه 28 آذر 1384, 18:19 عصر
ببین دوست من وقتی شما مثلا امیری رو وارد می کنی خوب لیست امیریها می آید بعدش چی می خواهی بشه روی اولین امیری وایمیسه .

soroosh_i58
سه شنبه 29 آذر 1384, 07:43 صبح
بله روی اولین امیری وایمیسه.... ولی اگه من چهارمین امیری رو انتخاب کنم و focus رو از اون کنترل بگیرم باز هم روی اولین امیری وایمیسه و نه روی چهارمین امیری که من انتخابش کرده بودم...

علی کلاهدوزان
سه شنبه 29 آذر 1384, 11:43 صبح
چون درون دیتابیست پرشی انجام نمیشه . این پرش رو در قسمت دیتابیست انجام بده نه در قسمت اینتر فیس COMBO ببین اطلاعات درون دیتابیس رو مثلا بر حسب چهار حرف اول فامیل سورت کن . با تغییر مقدار یک TEXTBOX مخفی درون فرم مقدار اون تکست باکس رو درون دیتابیس سرچ کن و اون رو استفاده کن . جیگر

soroosh_i58
سه شنبه 29 آذر 1384, 14:46 عصر
ممنون از راهنمایت... من فکر میکنم بتونم از طریق شی binding context پرش رو انجام بدم...اما نمیدونم چطوری با داشتن مقدار یک فیلد میشه به رکورد مورد نظر seek کرد میشه راهنماییم کنی؟