|
You can use foreach to step over the items in the listbox, then if you find one that matches ( using whatever rules you want ) then you can make an item selected. Something like
string searchString = tbSearch.Text.ToLower();
foreach(ListBoxItem item in lbItems.Items)
{
if (item.Text.Length >= searchString.Length)
{
if (item.Text.SubString(0, searchString.Length).ToLower() == searchString))
{
item.Selected = true;
break;
}
}
}
This code does not unselect the item selected before, but if the box is set to single select, that won't be an issue.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Launching a new VB dialect? Happens to me too!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
LOL - I wrote that without testing it, I suspect the semicolon will be the least of the issues with it. Hopefully it was close enough to push him in the right direction.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I was a little freaked by the code, but got the general idea of what you were trying to say.
Again I appreciate all the help. This is a great site to get ideas for things and how to do things.
|
|
|
|
|
Actually the easiest way to achive this is much simpler:
put this in the dropdown_textchanged event:
Me.ListBox1.SelectedIndex = ListBox1.FindString(Me.ComboBox1.Text)
|
|
|
|
|
Thanks. I'll try that.
I knew it had to be something I wasn't doing just right.
|
|
|
|
|
if statement using
A.Satheesh
|
|
|
|
|
Is this possible to scroll text in status bar?
Thanks In advance
Ejaz
|
|
|
|
|
There's no support for this built into the control, but you can add your own by creating your own version of the class.
|
|
|
|
|
hi iam new vb learner, i got a problem how to call function that return object it always said object variable not set but i think i already call it as object, is that in my code how to call object something wrong ?
--------------------------------------------
Public Function accessinfo() As Object
Dim myFSO, f As Object
Dim filename As String
On Error GoTo errhandler
filename = fillist.Path + "\" + fillist.filename
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set f = myFSO.GetFile(filename)
txt_datecreated.Text = f.DateCreated
txt_dateaccess.Text = f.DateLastAccessed
txt_datemodified.Text = f.DateLastModified
txt_size.Text = (Format((f.Size / 1024) / 1, "##")) + " kilobyte "
Exit Function
accessinfo = f
errhandler:
MsgBox "No File selected !. Please select the file ", vbCritical, Warning
End Function
-------------------------------------------------------
and then i want to call function accessinfo in getinfo
Private Sub cmd_getinfo_Click()
Dim fso As Object
Set fso = accessinfo
MsgBox (fso.DateCreated)
End Sub
|
|
|
|
|
|
I may be wrong in this but you have 'Exit Function' before 'accessinfo=f' to the function is trying to return to its caller before the object has been set. Why not try removing the 'Exit Function' and the 'accessinfo=f' and just replace it with 'Return f'?
|
|
|
|
|
Your Exit Function is preventing the "accessinfo = f" assignment from executing. Once you fix that, you will have to add "Set" to the object assignment. - "Set accessinfo = f".
Tom Garth
Developer
R. L. Nelson and Associates, Inc., Virginia
|
|
|
|
|
hi
i am facing one problem at the time of desinging 2 combobox from one datasource & one datatable. my data table contains following fields -
item_code | length | rate
xyz | 1000.00 | 2.0
bnm | 500.00 | 1.0
qwe | 300.00 | 0.50
i have to select rate for the selected item code & selected length. for this i am desiging two combobox separately but after selection of 2nd combo popup contents of 1st combo clearing. is there any solution using multicolumn combo or datagridview in 2005 ? if yes - how?
plz. help me
Thanks
bye
|
|
|
|
|
Each combo requires its own separate dataview as the datasource. The two dataviews 'point' to the same table. If you don't do this then each combo is using the table's default dataview as the datasource and a selection in one combo then affects the contents of the other.
-- modified at 10:26 Sunday 19th August, 2007
|
|
|
|
|
hi
thanks. my problem is solved using two data sets to access same datatable twice. i was doing same datasets to access same table twice.
bye.
Thanks
bye
|
|
|
|
|
Hi,
Try this...
Dim dvItemCode as New DataView(DataTable)
Dim dvLength as New DataView(DataTable)
Dim dvRate as New DataView(DataTable)
ComboBox1.DataSource = dvItemCode
ComboBox1.DisplayMember = "Item_Code"
ComboBox1.ValueMember = "ID"
ComboBox1.DataSource = dvLength
ComboBox1.DisplayMember = "Length"
ComboBox1.ValueMember = "ID"
...
Hope this helps
|
|
|
|
|
hi
thanks for immed. reply & sorry for late reply
i have done like u said but it shows one error -
Error - 'can not bind to the new display member.'
ParameterName : newdisplaymember
my code is as follows -
con.connectionstring = con_str
da_combo1.selectcommand =new sqlclient.sqlcommand
da_combo1.selectcommand.connection = con
str_sql = "select * from dbo.rate_mas"
da_combo1.selectcommand.commandtext = str_sql
da_combo1.fill(ds,"rate_mas")
dim dt as datatable = new datatable("rate_mas")
dim dvitemcode as new dataview(dt)
dim dvlength as new dataview(dt)
dim dvrate as new dataview(dt)
combo1.datasource = dvitemcode
combo1.displaymember = "item_desc"
**** it shows the above said error for immed. following stmt
combo1.valuemember = "item_code"
******** error end
combo1.datasource = dvlength
combo1.displaymember = "length"
combo1.valuemember = "id"
what can i do to solve this error
bye
Thanks
bye
|
|
|
|
|
Hi,
first please make sure that you are not trying to assign columns of two different tables to ValueMember and DisplayMember. In your case you have to check that item_desc and item_code belong to rate_mas datatable.
Good luck
|
|
|
|
|
I am trying to use VB.Net as a front end for a MS Access database. I am trying to get the date/time into a format I want to use(displaying, modifying etc). I have the field in Access defined as date/time. I only want to use the time portion in 24hr format. My format is HH:nn:ss and the input mask reflects this. When I display one record in VB.Net, the date is the only thing that is showing and instead of showing today's date, it is showing a date from 30 Dec 1899. The data I already have stored in the Access database for that field is 23:55:00. What do I need to do in order to get it to work the way I would like?
|
|
|
|
|
You are displaying the date in the text box in the wrong format. You can reformat the date in a textbox like this:
Dim MyDate As DateTime = Me.TextBox1.Text
Me.TextBox1.Text = MyDate.ToLongTimeString()
How did you setup the Dataset, etc? (Wizard or code) There is probably a better way of doing it if you could explain.
Green2Go
|
|
|
|
|
I set up the dataset through a wizard. The only thing I have coded an event on closing to update the database.
Public Class frmSingle
Private Sub DataBindingNavigatorSaveItem_Click(ByVal _ sender As System.Object, ByVal e As System.EventArgs) _ Handles DataBindingNavigatorSaveItem.Click
Me.Validate()
Me.DataBindingSource.EndEdit()
Me.DataTableAdapter.Update _(Me.TandemsheetsDataSet.data)
End Sub
Private Sub frmSingle_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) _ Handles Me.FormClosing
Me.DataTableAdapter.Update _(Me.TandemsheetsDataSet.data)
End Sub
Private Sub frmSingle_Load(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load
'TODO: This line of code loads data into
'the 'TandemsheetsDataSet.data' table. You can
'move, or remove it, as needed.
Me.DataTableAdapter.Fill _ (Me.TandemsheetsDataSet.data)
End Sub
End Class
|
|
|
|
|
Does your format really have "nn", or is that just a typo?
Tom Garth
Developer
R. L. Nelson and Associates, Inc., Virginia
|
|
|
|
|
It was "nn" because that is what Access used as the minute placeholder in the custom format. Access probably uses it to distinguish from the month for which it uses mm. At least it is working that way.
I think I might have found what I am looking for though.
In VB on the properties for the textbox I am using, I changed the Format property to Custom and changed the CustomFormat property to HH:mm:ss. It works the way I want it to now. Thanks to Tom and green2go for attempting to help me.
|
|
|
|