|
In VB.NET, something like this...
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown<br />
Dim item As Integer<br />
For j As Integer = 1 To ListBox1.Items.Count<br />
Dim rect As System.Drawing.Rectangle = ListBox1.GetItemRectangle(j - 1)<br />
If rect.Contains(e.X, e.Y) Then<br />
item = j - 1<br />
Exit For<br />
End If<br />
Next<br />
ListBox1.SelectedIndex = item<br />
End Sub
At least, it worked for me.
And, you could test to see if it was the right-mouse button first, too. I had this sample working with a context menu assigned to the ListBox, as well.
|
|
|
|
|
Thank you that worked great. Do you know what the code would be for a 6.0 App. I want to use this in some of my 6.0 applications.
|
|
|
|
|
Something like this -- though bear in mind this needs to be refined, as it will error out if there are less than items currently populated in the list, and items should be defined as the total number of list items the list is capable of displaying.
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim items As Integer
Dim averageHeight As Integer
items = 14
averageHeight = List1.Height / items
For i = 1 To items
If Y > (((i - 1) * averageHeight) + 1) And Y < (i * averageHeight) Then
List1.ListIndex = i - 1
End If
Next
If Button = 2 Then
Form1.PopupMenu rclOne
End If
End Sub
|
|
|
|
|
Hey !
I am a mech. engr. student and am having to put up with this course - intelligent robotic control.
The robots (amigobots) can be controlled by Java code that uses IP or whatever..!!!
I have done all my coding for Motion and Path Planning in VB. Is there any way I can access the bots' Java Classes from my VB appl. ?
Really desperate for this! Dont tell me to rewrite the entire code in Java...I am very new to programming...
Sairam Samavedam
|
|
|
|
|
Unless I'm mistaken, this could be an amazingly complex, yet interesting, project. there's an article on this subject here or you can go to java.sun.com and look up documentation on the JNI (Java Native Interface). I don't find much in the VB world that provides shortcuts for this, either.
|
|
|
|
|
I've found the same complexities. If your in a time crunch, it looks like your best bet is to start rewriting in Java. At least, with the VB code already written, you don't have to reinvent the logic.
RageInTheMachine9532
|
|
|
|
|
Thanks guys for the supp..
Anyway, came to know about an appl. called JavaReg, that comes with Jdk1.3
This thing is supposed to convert a Java class into a COM object that can be used in VB code.
Have tried it and it is not working some of the times. Like, it is not showing some of the methods in the created COM object that were supposed to be there.
If anyone have used JavaReg before, would like to know some info. on how to use it correctly.
Sairam Samavedam
|
|
|
|
|
Yeah. I tried it once, but never could get it to work reliably. I was just messing around with it though. I didn't need it for any particular project and just dropped it at that point.
RageInTheMachine9532
|
|
|
|
|
Did u ever try any of the tools that supposedly convert a VB code into Java code... ? Do they work? Any good ones ?
Going to all this trouble because rewriting would be painful, even though logic is done. Have to implement Digkstra's and visibilty graph algos...
Sairam Samavedam
|
|
|
|
|
Of the few language conversion tools I've used, they ALL have one thing in common:
They can never get all the code to convert properly, so you have to go thru and edit the resulting code anyway.
RageInTheMachine9532
|
|
|
|
|
I am writing a VB.NET applicatio that dumps data to an Excel Spreadsheet. After the dump is completed, I want to prompt the user to save the spreadsheet by showing the SaveFileAs dialog Box. The statement:
Result = EXL.Dialogs(Excel.XlBuiltInDialog.xlDialogSaveAs).Show Argl:= fName
Where fName is the file name, doesn't work form VB. The Argl:= fiName part of the statement generates asyntax error - "End of statement expected".
How can I make this work in VB.Net?
Thanks!
Nelson
|
|
|
|
|
I am writing a VB.NET application that dumps data to Excel. After the dump, I want to prompt the user to save the file by showing the SaveFileAs Dialog Box. I am having trouble setting the default file name in the Dialog Box with the statement:
Result = EXL.Dialogs(Excel.XlBuiltInDialog.xlDialogSaveAs).Show Argl:= fName
VB.NEt indicates a syntax error (End of statement expected)
The equivalent statement works in Excel, what am I doing wrong?
Thanks!
Nelson
|
|
|
|
|
The syntax "Argl:= fName" shouldn't work in VB.NET. I believe that you simply pass the file name to the show method. Also, several people have written introductions to using Excel and Word in VB.NET and C#, you might try those if you have other problems.
|
|
|
|
|
Hi guys (again!)
Some of you may have been folowing my escapades with the Excel Object model, and many thanks to those that have offered assistance!
So today's problem is as follows....
Have a column containing dates (Action dates). Each value in the column can be in either one of three states based on the values in two other date cols( Start date and End date). The values can either be accepted - i.e. between the two other dates, and therefore green, Not accepted, i.e. outside the dates and therefore Red, or Default - a value read from a SProc in an SQLServer db, and hence Blue.
Now using conditional formatting, can use xlCellValue type, and compare based on the two cols for Accepted / Not accepted, and this seems to be OK, however, I cannot seem to make it work for the default values. I'm using the following code:
<br />
strCondString = "=$I$" & CStr(lPos) & "=" & dtDefault<br />
<br />
With oWS.Cells(lPos, "I").FormatConditions.Add _<br />
(Type:=xlExpression, Formula1:=strCondString)<br />
<br />
With .Font<br />
.Color = RGB(0, 0, 255)<br />
.Bold = True<br />
End With<br />
<br />
End With<br />
where lPos is a row reference, and dtDefault is the date. strCondString will evaluate to something like "=$I$2=12/01/2004"
The code seems to get through the compiler, in that it doesn't throw any errors when steppping over, but also doesn't colour the text at all - it stays black.....anyone?
To add confusion (and not looked at this bit yet), how will it all stack up when I throw in the colouring for Accepted - all default dates will be "accepted", so is there any precedence in the FormatConditions that anyone knows about?
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
Instead of relying on Excel's FormatConditions to perform conditional formatting, couldn't you rely on conditional logic instead, like so?:
Public Sub HighlightColor()
Dim i As Integer
For i = 1 To Range("MyRange").Rows.Count
If Not (Cells(i, 8).Value <= Cells(i, 9).Value And Cells(i, 9).Value <= Cells(i, 10).Value) Then
Cells(i, 9).Font.ColorIndex = 3 ' Red
End If
Next
End Sub
Or should the condition be in place for when someone interacts with the worksheet?
|
|
|
|
|
John Kuhn wrote:
Or should the condition be in place for when someone interacts with the worksheet?
Unfortunately, you've hit the nail on the head! Am developing a utility to generate the spreadsheets based on different date ranges, which will then be used by others to enter data - hence the need to have all the formatting stuff in place before the user gets the sheets - it's not just a VBA project, but a full VB6 executable.
Have managed to get around it though, by putting the default dates into a hidden column, and then using xlCellValue rather than xlExpression.
Many thanks for the help though - hope I can return the favour some day!
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
You should have come to me, I could have got you the answer wholesale...
Steve S
|
|
|
|
|
I have filled Combobox value by setting DataSource property, giving Display Member and Value Member, for a particular Table fields in Access-2000 database. I selectd some value of combobox. now when i load that form again, i want to set the previously selected value of combobox. have tried using combobox1selectedvalue = code, also tried out by setting combobox1.text, combobox1.selectedtext, but none of them is working.
Its very important will be thankful and grateful if anyone can pull me out of this problem.
Thanx
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
How about combo1.listindex = lSomeVal . Would that fit the bill
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
No its not working pal
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
I use the code below to do what (I think) you need to do...
<br />
'Now set the combo to show the propDB stored in the .ini file<br />
For i = 0 To cmbPropDB.ListCount<br />
If cmbPropDB.List(i) = gstrPropDB Then<br />
cmbPropDB.ListIndex = i<br />
Exit For<br />
End If<br />
Next i<br />
The thing that might be causing it to work on my machine and not on yours is because I've set my combo box type to DropDownList - this means that the user can't type directly into the edit area, but must select from the list.
Let me know a bit more info, and will see if can sort it out for you if you like...
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
Hello everybody,
How can I implement navigation methods such as MovePrevious on collection objects in Visual Basic 6.0?
Also, is there a fast way to search a collection object on some attributes of classes it stores, other than keys or ids?
Regards,
Roozbeh.
|
|
|
|
|
Here are the options I know of:
1) You can write your own custom class that "inherits" the VB6 collection object. Of course VB6 doesn't really inherit, you simply wrap calls to the collection object with methods of your own class (is that a wrapper or a decorator...)
2) You can write a method of that class that searches through the collection for a particular value.
3) You can look around for a custom control or library written by someone else.
|
|
|
|
|
How can I access shared folders on a remote machine using vb.net??
|
|
|
|
|
How are you establishing the connection to the remote machine, using what connectivity? FTP? HTTP? NTLM?
|
|
|
|