|
I need to seacrh a simple customer database. As the user types in letters to a textbox, the a listbox filled with all available options will highlight the closest option to what is being typed.
e.g. in textbox "j" is typed
Listbox highlights "jim"
When "jo" is typed the list should highlight john
How would i search the database (sql) for the closest match on the text_changed event
I am using Visual studio 2005, a dataset, binding source and table adapter.
P.S. Would it be possible to search a list box in the same method without actually searching the source.
Posted by The ANZAC
|
|
|
|
|
You can filter the listbox by iterating over methods and using the string.Contains method.
select * from blah were col LIKE @param + '%'
will find all strings that start with @param.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanx Christian, i found an easier way though...FindString, this searches the listbox as the user types, as this changes, the listbox highlights the most relevant item, and because all my controls are databound to the same source, this then displays the correct information in the other fields i have.
Dim i As Integer = Me.lstLast.FindString(Me.txtSearchLast.Text)<br />
Me.lstLast.SelectedIndex = i
Posted by The ANZAC
|
|
|
|
|
How do i reset 1st item for combolist VSFlexGrid to blank after load the data from database, eg:
If adoRset.RecordCount > 0 Then<br />
grdPeriods.ColComboList(grdPeriods.colIndex("VintageID")) = grdPeriods.BuildComboList(adoRset, "VintageCode", "VintageID")<br />
End If
Thanks
Angela
|
|
|
|
|
This script works great on the XP box I wrote it on but not on a Win 2000 box.
The script was found while Googling and I have added the rename sub and a few other changes to suite my required task.
I am reletivly new to dev and am not sure if the problem is win2k supporting the script or if the script needs changing.
The problem is at line 70 creating the tcp ip ports. if I take this out the script runs to completion telling me the printers are added but they are not.
I manually added the ports and re ran the script but no luck.
Please help...
<br />
'This script will add ip ports for your local printers and attach printers to<br />
'those ports. Just edit the arrays to reflect the paths for the .INF files<br />
'and get the printer descriptions from the .INF files. If the printer is listed<br />
'in the system32/inf/ntprint.inf use that as the .INF it tells the script where<br />
'to look for the driver otherwise use the UNC path to get the path.<br />
'===================================================<br />
strComputer = "."<br />
'strComputer can be an array of netbios computer names or<br />
'ip addresses put into a for loop<br />
'===================================================<br />
<br />
Public Error<br />
Dim Count:Count=0<br />
Set WshShell = WScript.CreateObject("WScript.Shell")<br />
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")<br />
<br />
<br />
Wscript.echo "This process may take several minutes please be patient." & VbCrLf _<br />
& "Another pop-up box will inform you when it is finished."<br />
<br />
'Here is where your edit the port IP addresses<br />
'===================================================<br />
Dim IPArray<br />
IPArray = Array( "192.168.100.1","192.168.100.1")<br />
Dim PrintersArray<br />
'===================================================<br />
<br />
'Here is where you enter the driver inf paths<br />
PrintersArray=Array("C:\CanonDrivers\win2k_xp_PCLModBW\P52KUKAL.INF",_<br />
"C:\CanonDrivers\win2k_xp_PS_2-9\W2KPS3K.INF")<br />
'===================================================<br />
<br />
'Here is where you edit the printer names<br />
Dim PrinterNames<br />
PrinterNames=Array("Canon iR C5180 PCL5c", "Canon iR C5180 PS3")<br />
'===================================================<br />
<br />
'Here is where you edit the new printer names<br />
Dim PrinterNewNames<br />
PrinterNewNames=Array("Black and White", "Colour")<br />
'===================================================<br />
<br />
For n = LBound(IPArray) To UBound(IPArray)<br />
'Install the IP printer ports<br />
Install_IP_Ports IPArray(n)<br />
Next<br />
For n = LBound(IPArray) To UBound(IPArray)<br />
Count = Count + 1 'just increments the counter for the message at the end!<br />
'===================================================<br />
<br />
'Add the printers (Arguments: ip port, path to the .inf files, printer name)<br />
'get the name from the inf files or make one up!<br />
'===================================================<br />
<br />
Add_local_ip_printer IPArray(n), PrintersArray(n),PrinterNames(n)<br />
Next<br />
'===================================================<br />
<br />
'If only one printer in array set to zero e.g. PrinterNames(0) or comment out!=<br />
Make_Default_printer PrinterNewNames(0)<br />
<br />
'===================================================<br />
'Install the TCP/IP Port(s):<br />
Function Install_IP_Ports(strIPAddress)<br />
<br />
Set objWMIService = GetObject("Winmgmts:")<br />
objWMIService.Security_.Privileges. _<br />
AddAsString "SeLoadDriverPrivilege", True<br />
<br />
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_<br />
objNewPort.Name = strIPAddress<br />
objNewPort.Protocol = 2<br />
objNewPort.HostAddress = strIPAddress<br />
objNewPort.PortNumber = "515"<br />
objNewPort.Queue = "lp"<br />
objNewPort.SNMPCommunity = "public"<br />
objNewPort.SNMPEnabled = False<br />
objNewPort.Put_<br />
<br />
'stop the spooler<br />
Set colServiceList = objWMIService.ExecQuery _<br />
("Select * from Win32_Service where Name='Spooler'")<br />
For Each objService In colServiceList <br />
errReturn = objService.StopService()<br />
WScript.Sleep 1000<br />
Next<br />
<br />
'start the spooler<br />
For Each objService In colServiceList<br />
errReturn = objService.StartService()<br />
WScript.Sleep 5000<br />
Next<br />
<br />
End Function<br />
<br />
Function Add_local_ip_printer(strIP,strPath_To_Inf_Files,strPrintername)<br />
<br />
WSHShell.run ("CMD.EXE /C RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b "_<br />
& chr(34) & strPrinterName & chr(34) & " /f " & chr(34) _<br />
& strPath_To_Inf_Files & chr(34) & " /r " & chr(34) _<br />
& strIP & chr(34) & " /m " & chr(34) & strPrinterName & chr(34) _<br />
& " /q /u"),0,True<br />
<br />
ReNamePrinter strPrintername,PrinterNewNames(n)<br />
<br />
End Function<br />
<br />
Function ReNamePrinter(prnName,prnNewName)<br />
<br />
Set objWMIService = GetObject("winmgmts:" _<br />
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />
<br />
Set colPrinters = objWMIService.ExecQuery _<br />
("Select * from Win32_Printer Where DeviceID = '" & prnName & "'" )<br />
<br />
For Each objPrinter in colPrinters<br />
objPrinter.RenamePrinter(prnNewName)<br />
'objPrinter.Put_<br />
Next<br />
<br />
End Function<br />
<br />
Function Make_Default_printer(strPrinterName)<br />
<br />
Set colInstalledPrinters = objWMIService.ExecQuery _<br />
("Select * from Win32_Printer") <br />
For Each objPrinter in colInstalledPrinters<br />
If objPrinter.Name = strPrinterName Then<br />
objPrinter.SetDefaultPrinter()<br />
End If<br />
Next<br />
<br />
End Function<br />
<br />
Wscript.echo "Install completed, please check you have 2 printers added" & VbCrLf _<br />
& "One named 'Black and White' and the other named 'Colour'"<br />
'End Script<br />
When people make you see red, be thankful your not colour blind.
|
|
|
|
|
Hi,
I need to round the minutes to the nearest queater of hour. For example if it is 00:07 (hour:minutes) then it would be 00:15, if 00:05 then it would be 00:00.
Any ideas how to go about doing this?
Many thanks for your time.
|
|
|
|
|
you can use an if elseif then statement to accomplish this task or even a select case. Are you pulling the time from the Now function and if so then you will need another var to hold the rounded time value.
Recreating the wheel is the best way to appreciate what the previous coders have gone through to get you where you are now.
|
|
|
|
|
Here is an example of what I was talking about using the if elseif then statement. This assumes you have two labels on a form named Label2 and Label3.
Private Sub Load_Time()
'calculates the rounded time
Dim newtime As DateTime
Dim min As Integer = Now.Minute
Label2.Text = Now.ToShortTimeString
If min >= 0 And min <= 15 Then 'First Quarter
If min > 7 Then
'move up
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 15, Now.Second)
Label3.Text = newtime.ToShortTimeString
Else
'move down
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 0, Now.Second)
Label3.Text = newtime.ToShortTimeString
End If
ElseIf min > 15 And min <= 30 Then 'Second Quarter
If min > 22 Then
'move up
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 30, Now.Second)
Label3.Text = newtime.ToShortTimeString
Else
'move down
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 15, Now.Second)
Label3.Text = newtime.ToShortTimeString
End If
ElseIf min > 30 And min <= 45 Then 'Third Quarter
If min > 37 Then
'move up
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 45, Now.Second)
Label3.Text = newtime.ToShortTimeString
Else
'move down
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 30, Now.Second)
Label3.Text = newtime.ToShortTimeString
End If
ElseIf min > 45 And min <= 59 Then 'Fourth Quarter
If min > 52 Then
'move up
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour + 1, 0, 0)
Label3.Text = newtime.ToShortTimeString
Else
'move down
newtime = New DateTime(Now.Year, Now.Month, Now.Day, Now.Hour, 45, Now.Second)
Label3.Text = newtime.ToShortTimeString
End If
End If
newtime = Nothing
min = Nothing
End Sub
Recreating the wheel is the best way to appreciate what the previous coders have gone through to get you where you are now.
|
|
|
|
|
Hi,
I have a VC++/MFC application.
I decided to move the UI to VB.NET to improve it.
I created a VB project with new interface and moved the C++ core into a MFC dll project.
When I run the application I got 'Stack owerflow' inside the MFC code.
For code details:
The C++ code does image processing using some recursive functionality, that is the point where the stack sucks up.
It happens when I passing over 4400 iterrations (the maximum is about 12000).
The recursive function looks like this
// Check for continous black areas
void CBitmapScan::CheckAround(CRect* pBound, int nX, int nY)
{
if(oMemDC.GetPixel(nX, nY) == RGB(0x00, 0x00, 0x00))
{
// Remove the pixel to avoid duble-check
oMemDC.SetPixel(nX, nY, RGB(0xff, 0xff, 0xff));
// Set new bounds
if(pBound->left > nX) pBound->left = nX;
if(pBound->right < nX) pBound->right = nX;
if(pBound->top > nY) pBound->top = nY;
if(pBound->bottom < nY) pBound->bottom = nY;
// Check up-down-left-right
CheckAround(pBound, nX + 1, nY);
CheckAround(pBound, nX - 1, nY);
CheckAround(pBound, nX, nY + 1);
CheckAround(pBound, nX, nY - 1);
}
}
Why this happening?!
Thanks in advance
Peter
|
|
|
|
|
I'm creating this asteroids-like game in vb for this vb class that I'm in and I need to be able to have multiple keys performing their functions at the same time. I am currently using the preview key down event for each of the keys but with that if you have one key pressed down and press another one it stops performing the operations of the first key. My professor said i needed something like asynchronous key detection but I couldn't find anything on it in the searches i did. Can anyone help me out?
|
|
|
|
|
You need to use DirectX for this. Direct Show is going to give you that sort of control over keys. The other option is to pinvoke GetAsyncKeyState or GetKeyState.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I feel like this should be an easy task, but I am having some issues.
I have a tab control, call it tabControl1, and 8 tabs, call them tabPage1 - 8. The length of the text on each tab is different. I want to create a 'justified' look and put the tabs in two rows (similar to MS Word tools>options).
I can adjust the padding, which changes the padding for all the tabs. But when I do this, the longer of the two rows appears to float.
If anyone could give me some guidance on this or point me in the right direction I would appreciate it.
Thanks in advance.
|
|
|
|
|
I converted VB.NET 1.1 Windows application to 2.0.
It's MDI application with many MDI children.
Now I got strange error. When few diffrent MDI children opened at the same time, and then you close one child , the whole MDI parent form falls into infinite loop like trying to redraw other child. And there is no other way to stop it, but close application using Ctrl+Alt+Delete. The funny thing is it happen not with all children forms, but I cannot find the rule or reason why.
Can someone help?
Thank you in advance.
|
|
|
|
|
trying again
dim frm as childform
Click_event...
frm =new childform
frm.mdiparent=me
frm.show
|
|
|
|
|
Thank you for the response.
That was exactly what I was doing. And I found the cause of this error. Most of the child forms have Maximized state and that what makes error.It looks like form starts draw and redraw header of the form and maximize it in a endless loop. As soon as I set it to Normal, the error gone. Instead on a Load event i resized the child form to Client area of MDI form and also removed maximized button. It solved the problem, but it is not how I expected make it. I have about 60!!! child forms and I need to open each one and change setting.
|
|
|
|
|
Hi everybody,
I found some code to hook, low-level, the keyboard and the mouse.
After some changes to get it working with vb 2005, I get the following error:
"CallbackOnCollectedDelegate was detected ....."
This is some of the code:
Private Function LowLevelKeyboardProc( _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As KBDLLHOOKSTRUCT) As Integer
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or _
wParam = WM_SYSKEYDOWN Or _
wParam = WM_KEYUP Or _
wParam = WM_SYSKEYUP Then
Return 1
End If
Return CallNextHookEx(hhkLowLevelKybd, _
nCode, wParam, lParam)
End If
End Function
Private Delegate Function LowLevelKeyboardProcDelegate( _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As KBDLLHOOKSTRUCT) As Integer
Public Sub EnableKeyboard()
UnhookWindowsHookEx(hhkLowLevelKybd)
End Sub
Public Sub HookKeyboard()
Dim callback = New LowLevelKeyboardProcDelegate(AddressOf LowLevelKeyboardProc)
KeyboardHandle = SetWindowsHookEx(WH_KEYBOARD_LL, _
AddressOf LowLevelKeyboardProc, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
GC.KeepAlive(callback)
End Sub
Doe someone knows what is going wrong?
Thanks,
Jurgen
|
|
|
|
|
Hi all
I am developing a VB application in which I have created a translucent form using SetLayeredWindowAttributes API. On sharing of this application using netmeeting or windows messenger the client system is unable to view the application properly. Kindly suggest.
Thanks in advance
Regards
|
|
|
|
|
There's nothing you can do. Layered Windows are not supported acrossed NetMeeting sessions. PrintScreen even has problems with it!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Is there any other way to make the form translucent which will be supported across Netmeeting sessions.
|
|
|
|
|
Nope.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi;
I have a field of type 'image' in a table where files are stored in binary form. How would I download the file in its actual form in vb.net or ASP.NET.
I use the ADODB.STREAM CLASS in Visual Basic 6 for this purpose but having problem in ASP.NET
BYE
|
|
|
|
|
Put this code in your page
Dim oAttachment As New GetAttach
Try
Me.Page.Response.Clear()
Me.Page.Response.ClearContent()
Me.Page.Response.ClearHeaders()
Response.ContentType = ""
Response.BinaryWrite(oAttachment.GetAttach(<The Id of your stored file>))
Response.AddHeader("content-disposition", "attachment; filename=" + oAttachment.ATTACH_NAME + "." + oAttachment.EXTENSION)
Me.Page.Response.End()
Catch ex As Exception
throw ex
End Try
GetAttach Class to call getter stored procedure
Public Function GetAttach(ByVal MyParameter As Integer)
Dim docFileReader As SqlDataReader
Try
Dim Myadapter As New SqlDataAdapter
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Using command As New SqlCommand("GetAttachment", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add(New SqlParameter("@MY_SP_PARAMETER", MyParameter))
connection.Open()
docFileReader = command.ExecuteReader
docFileReader.Read()
EXTENSION = docFileReader.Item("EXTENSION").ToString
ATTACH_NAME = docFileReader.Item("ATTACH_NAME").ToString
WEIGHT = docFileReader.Item("WEIGHT").ToString
Dim FileData(docFileReader.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
docFileReader.GetBytes(0, 0, FileData, 0, FileData.Length)
docFileReader.Close()
Return FileData
End Using
End Using
Catch ex As Exception
If IsNothing(docFileReader) = False Then
docFileReader.Close()
End If
Throw ex
End Try
End Function
|
|
|
|
|
How to create a page in which there is a static panels that remains static even if the page moves.
punam
|
|
|
|
|
Set the panel's max and min size to be the size you want.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If u want the panels to change and be related to the form...u may set the dock and anchor properties to the right selection.
and vise versa if u want the plane to be static and not changing its size even if the form's size had been changed, then u also go to the dock and anchor and set default selection for both of them
|
|
|
|
|