Selected Case Of A Listbox Isn't Working As Expected
Apr 10, 2010Selected Case of a Listbox isn't working as expected
View 2 RepliesSelected Case of a Listbox isn't working as expected
View 2 Repliesmy vb.net will not use listbox1.selecteditems it always comes up with a blue line underneath even though when i search online everyone is using this. my goal is to get the selected items and list them in a textbox
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim li As ListItem
For Each li In ListBox1.Items
[Code]...
It looks like impossible but...
Try
Select Case command
Case 1
smth()
Case 2
[code]....
Firstly Case 2 runs. Throws exception. And right after this debugger shows that next processed statement is Case Else. Only after Case Else throws own exception Catch block start working. I've never seen this trick. Why can this happened?I'm sure the block is entered once (not like this:first enter hit Case 2 and second hit Case Else).
Update:-To Matt Wilko. Thank you for answering. I've switch to Strict On in Options of VS2010 but nothing has changed. Command is variable, not function. Watch tool shows that on each step Command is the same ( Command = 2).
Fixed. Yeeaaaahhh. I simplefy code to
Try
Select Case 2
Case 2
[code]....
and change project to Console app. This works as I mention. The fix was in Release mode. I was debugging in Release mode. When I switch to Debug mode everything goes as it should.
I have an Excel worksheet with a Source Cell and a Target Cell.Via GDI API functions, I draw a temporary gradient fill over the source cell which happens to be cell "D6"then, I make a transparent copy of the temp gradient fill drawn over the source cell and place the copy (ie the transparent gradient fill) over the target cell which happens to be cell "D9".
View 3 RepliesI want to fetch data from a database table modify it and update it without being dependent on the database provider and the database structure, because it will be part of a library.My first attempt was as follows:
'factory defined somewhere else as DbProviderFactory
'connection is a working DbConnection
Dim selectcmd As DbCommand = connection.CreateCommand()[code]....
it did not work. After further investigation I figured out that the Commands the CommandBuilder generated were useless, because it inserted ? instead of @param1 for all Parameters. It generated something like INSERT INTO tbl1 (field1, field2, field3) VALUES (?, ?, ?) for the InsertCommand.I would really like to use the CommandBuilder, because it is simple and I don't have something complicated like JOINS.
I have a query like so:
Dim clcexists = (From p In dbContext.Signatures _
Where p.StudentID = people_id _
And p.ContractType = "clc" _
Order By p.ID Descending _
Select p)
Later I check whether any rows exist in clcexists using IsNothing like so:
If IsNothing(clcexists) Then ' If no CLC is on file.
clcfirst = Date.Now.Subtract(year)
clcdate = clcfirst
[Code]....
But IsNothing() is not functioning like I expect. There is no row in the results table, but it is still acting as if there is and going to the Else clause.
I am running Windows 7 pro and using Visual Basic 2010 express.I have written a small program to switch on a USB relay which is controled by a serial port.I have debuged the program and it appears to work correctly. I have published the program and if I start it from thr run menu / desktop shortcut / or through explorer it works as expected.
However I have tried to run it by the Task Scheduler and then it fails to run as expected. I have a small section of code that checks to see if the serial port is present if not I have used messagebox.show to ask for the relay to be pluged in. In every case other than when running through the Task Scheduler the messagebox works with the Task schedulerit doesn't show the messagebox and the program hangs I have included the code I have used.
Dim retry As Boolean = False
Dim data() As Byte = {255, 1, 1}
Do Until retry
[code]....
[URL]. I have a Multi-Line textbox with several accounts in it. They are in email@email.comassword format on separate lines. All the code is right, but it goes really weird and loops like 3 times before logging in. Eventually logging into the last account on the Textbox instead of the first. It should just login to the first account...Logout....Login to the second account...Logout and continue the process.
If you want to test it, just put a web browser and a textbox1 multiline box, a button and enter a few working hotmail accounts and you'll see.
Check line 17
Looks like a lot of code, but line 17 is the only bit that needs to be looked at. The rest is just junk/non-relevant to this problem. It separates the accounts perfectly and stuff, but just wont login in the right order.
I have declared a String variable(PC) for use within another String variable(currentQuery) to form a SQL statement to pass to my SQLDataAdapter variable.
I'm performing this action to change the string variable(PC) for the different onClick events I have.
It seems i can change this variable (PC) within my onClick event handlers and the 'PC' variable will change when I apply it to a testing Text Box 'testTextBox' but not for the currentQuery variable.
Do i need to perform this action as a function or am i missing something obvious - code below - I don't want to spend time writing a function to return a string value for my SQL statement if i can just tweek something in my code (below).
Partial Public Class IVMain
Inherits System.Web.UI.Page
Dim DBConn As New SqlConnection("Data Source=hnaServer;Initial Catalog=Hnastatus;User ID=Test;Password=test")
[Code]....
I have a form with a split panel. In the one split are a group of buttons which I want to programmatically change the color of the last pressed button.The following loop seems to run correctly and set the colors correctly but the form doesn't represent that. Once the loop is completed and I recheck the button colors, they revert to previous state.[code]I can get the desired effect by doing the below code but seems less elegant and would obviously require updates as buttons would be added or removed.[code]
View 2 RepliesI was toying around with some of the linq samples that come with LINQPad. In the "C# 3.0 in a Nutshell" folder, under Chater 9 - Grouping, there is a sample query called "Grouping by Multiple Keys". It contains the following query:
from n in new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable()
group n by new
{
[Code].....
I have the following code,
PB.ForEach(Function(x) x.Cost = GetPartCost(x.PartNumber, x.Units, x.Cost, FB))
Return PB.Sum(Function(x) (x.Cost * x.Qty))
However it always returns 0. I've checked and the GetPartCost function executes and returns a non-zero number but the list item cost properties are never updated.The property is just a simple property,
Public Property Cost() As Double
Get
Return _Cost[code]....
If I set a breakpoint in the Set of the property, it never gets hit.
I am working a building a form that is generated using Project|Add Windows Form|Form.
In the Load procedure, I placed the following code:
dbObject.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:scdbv4datascdbdata.mdb"
rsObject.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
[Code]......
Full Program: Option Strict On : Option Explicit On Module Module1
[Code]...
After I ran it, I had a file a.txt in my debug folder but the size is 0 bytes (and when i open it is empty of course) Shouldn't the output had "asd" in it ?
i think this is the right place to post this.so i am doing my First Vb project and have run into some problems
[Code]...
I had to change the given code from If Then to Select Case, and this is what I came up with. But when I run the program, it does not work and gives me zeroes instead of the correct information.
Public Class MovieInfo
Private wkndBox, screens As Integer
Private title As String
[Code].....
i need to make a statement that checks the remainder of a number divided by 4.[code]can i get this in SELECT CASE ..MOD format please
View 1 RepliesI have spend a couple of hours trying to figure out why my generic Dictionary(Of String, String) is not ignoring case.Here is my code:
Dim test As New System.Collections.Generic.Dictionary(Of String, String)(System.StringComparison.OrdinalIgnoreCase)
test.Add("FROG", "1")
[code].....
i need to change the selected value to upper case in the richtextbox i use the code
Dim tou As String
Dim tot As String
tou = RichTextBox1.SelectedText
tot = tou
[code]....
Public Function TitleCase(ByVal strIn As String)
Dim result As String = ""
Dim culture As New CultureInfo("en", False)
Dim tInfo As TextInfo = culture.TextInfo()
result = tInfo.ToTitleCase(strIn)
Return result
End Function
If I input "TEST" into the function above. The output is "TEST". Ideally it would output "Test". I also tried the code snippets from this post to no avail: Use of ToTitleCase.
I am trying to compare the contents of 2 collections in a unit test in .NET using MSTEST. To make things simple, instead of having to .Sort() and then loop through the collection and compare items one at a time, I've found the new and very cool .Intersect Extension method.
It seems to work great by doing:
Assert.AreEqual(expected.Count, actual.Intersect(expected).Count)
However, now that I have a test which needs to be case-sensitive, it breaks. I've tried sending Intersect's second parameter StringComparer.Ordinal,StringComparer.InvariantCulture, and StringComparer.CurrentCulture... no luck..
EDIT: here is the data:
Actual:
(0) "FOO" String
(1) "foo" String
(2) "Foo" String
[Code]....
It seems to be removing a matching duplicate 'foo', and a matching duplicate 'BAZ'. Perhaps there is a better way to assert collections are matching?
_EDIT2: I think Intersect() removes duplicates, which is why this is breaking. I Found the CollectionAssert Class.
I have a code to search for specified text in all listbox items. Here it is:
ListBox2.Items.Clear()
For Each item In ListBox1.Items
If item.ToString.Contains(TextBoxDropDown1.Text) Then
[code]....
This works fine. But if I have search for this:
"My Search"
I wont find this:
My sEarCh"
Is there any way to search for text of any casing, and if so how can I adapt my code to do this.
I have written the code below to check and see if the text the user entered into the txtbox already exists as an item in a listbox before adding the new item. This works well; however, if say "Fish" exists in the listbox but the user entered "fish" in the textbox, the item is added to the listbox. I do not want this because the item already exists. How can I modify my code so that the comparison is not case sensitive?
'Check to make sure the active medication does not already exists in the list
If lstActiveMeds.Items.Contains(strActiveMeds) = True Then
MessageBox.Show("The active medication you entered has already been added to the list.",
[code].....
I'm not sure why the following code is not working as intended:
CODE:
Where litMessage is the name of the literal control and messageBody is the name of the string variable.
My intention is to output a string onto a web page and to replace the line breaks with a br tag so that it can be displayed on the page correctly. However, nothing is replaced. When viewing the page source, it looks like the line breaks still exist in the string. Similarly, when displaying the string via MsgBox, it displays normally as well. I have also tried wrapping the output with the pre tag and it displays the line breaks properly as well.
The string was originally entered by a user through the use of an asp:Textbox and saved into a MSSQL database. It's retrieved and displayed on another webpage using an asp:Literal control. The only thing that happens to the string before it is submitted is that it is trimmed (i.e. textbox.Text.Trim()).
Perhaps there is something I did not consider?
Edit #1: Due to time constraints, I've decided to just wrap the text with the pre tag. It's an acceptable work around as it preserves the line breaks. Unfortunately, it doesn't explain why the code didn't work in the first place. In the meantime, I'll just leave the question unanswered until I find a proper answer.
Edit #2: Solution found and answered below. UpdatePanel tag added to the question for future reference.
I want set Listbox background to transparent but not working
View 3 Repliesi have a program using a select case to convert letters to special charaters. My question is how can I get the code to read upper and lower case letters without having to put the upper case letters in my select case statement. Example: Part of my code is
[Code]...
I have a repeater with a dropdownlist in it. When a user changes its index, I would like a label to change its value. (the ddlSizes values come from a MySQL DB)
[Code]...
i want to the textbox that when I start to type in names it should be like this Camille Aisha Cordova, How do I do this?
View 16 RepliesIm using a Random Pool number generator and was wondering how i can make it use upper-case and lower-case letters as well as numbers here is a pic
[Code]...
I have Listbox, that I want to assign primary key, and a text (eg. students table). So i wrote this code.
mySQLCmd.CommandText = "SELECT studentname, studentid FROM studentstable WHERE Year(DOB) = " + selectedYear
Dim dt As New DataTable
myReader = myCmd.ExecuteReader()
[code]....
When I select something on the listbox, both of selecteditem and selectedvalue properties just return the student name, not the student id. So I get this error.
Error on Line2. Conversion from string "RichardCole" to type 'Integer' is not valid.I don't know why? So i do i get the studentid value back ? I need to know the ID coz name can't use as PK so.