|
The combobox I populated from DB. WHen I add, update DB, this combobox is one field but if user doesn't select anything. The insert/update sql will not correct.
So how to detect this situation then warning the user.
|
|
|
|
|
If nothing is selected, the SelectedIndex property of the ComboBox instance will equal -1.
If (combo.SelectedIndex = -1)
End If
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
I have tried. If no selected (user does not do anything with the combobox) selected.index=0 the same when user select the first row.
I use Visual Studio 2013 and populate combobox from database using datatable like this
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
Cbx_PhoneType.DataSource = myDataSet.Tables("MyTable").DefaultView
Cbx_PhoneType.ValueMember = "ID"
Cbx_PhoneType.DisplayMember = "Model Name"
cmd.Dispose()
con.Close()
|
|
|
|
|
You could do the Following :
After populating the Combobox with new data you set an additional boolean Variable (ComboBoxHelper) to false.
If the Combobox is Clicked or SelectedIndexChanged you set this Variable to True.
Now you know, that the Combobox was used by the Operator ...
|
|
|
|
|
Do you have skype. I want to contact with you for detail solution.
|
|
|
|
|
No ... sorry ... but you could reply here and also we could discuss anything ...
|
|
|
|
|
I have tried your suggestion but I fail. Do you have any OTT application such as Viber, Whatsapp, line...... We can contact easier.
Thank for your help.
|
|
|
|
|
It either happens here on Code Project or it doesn't happen at all.
|
|
|
|
|
I think you read what Dave has written. My answer is the same - sorry ...
Back to your Requirement :
You have some ComboBoxes, ListBoxes and/or TextBoxes on your Form. All of them are assigned with some values. Your problem now (as I understood) is that the User has made some inputs but sometimes he forgot (or not realize) to make a selection on the Combobox. By default your Combobox has not SelectedItem= -1 - it has SelectedItem=0 (and this could be a valid selection).
So ... what could you do now ?
One possibility is to force the user to make a selection or to touch the Combobox.
The Suggestion I gave you is to touch the Combobox. But perhaps that doesn't matches to your Requirement (if you coded I in the right way it will work).
So we could change something : the content of your Combobox don't have a valid data on Item=0. This could be done if you first insert a "-" as Item and then the correct data.
Perhaps you think about that ...
|
|
|
|
|
Right after you populate the combo box, set the SelectedIndex property to -1. Then it will be -1 if the user hasn't changed it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If by chance you're using Windows Forms, the combobox has an event that fires only when the user makes a selection. It's independent of the SelectedIndexchanged event. Handle the event and get the SelectedIndex property from there.
ComboBox.SelectionChangeCommitted[^]
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
Buen día;
necesitaría un poco de ayuda.
Tengo un formulario de nombre "frmProcess" el cual contiene un StatusStrip de nombre "StaComment"
Por otro lado tengo un módulo el cual contiene la siguiente rutina:
Public Sub InitialMenu(lfrmActive as Form)
.
.
.
End Sub
Mi pregunta es, como hago para invocar al StatusStrip usando el parámetro form
Esto que estoy haciendo es una migración de un VB6 donde lo mismo se hacía de la siguiente forma:
Public Sub InitialMenu(lfrmActive as Form)
lfrmActive.staComment.Panels("Action").text=""
End Sub
Saludos
Translation:
od morning;
I'd need a little help.
I have a name form "FrmProcess " which contains a StatusStrip of name "StaComment "
On the other hand I have a module which contains the following routine:
Public Sub InitialMenu (lfrmActive as Form)
.
.
.
End Sub
My question is, how do I invoke the StatusStrip using the form parameter
This I am doing is a migration of a VB6 where the same was done as follows:
Public Sub InitialMenu (lfrmActive as Form)
LfrmActive. staComment. Panels ( "Action "). Text = ""
End Sub
Best regards
|
|
|
|
|
Go to the form, click on your statusstrip, and add a statuslabel. Go to properties, set "Modifiers" to public. Next, open your Module and change the code;
Public Sub InitialMenu (lfrmActive as Form)
lfrmActive.toolStripStatusLabel1.Text = "bla"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi ALl.
I populated combobox from DB.
And now when user select the value, how can i get the ID back.Because the selectedindex id diffirent from the original ID.
Thanks.
|
|
|
|
|
Depending on what type of application you're developing, the SelectedValue should give you either the selected database ID, or a DataRowView containing the values loaded from the database.
If it doesn't, then you've not set up the binding correctly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I just use comboboxname.text. It will be a text file. If you want to get something from the DB, forget the index and just use a sql statement "SELECT * FROM db WHERE value = '" & comboboxname.text & "'"
|
|
|
|
|
Use Value instead. Getting the ID from a table with millions of records is much quicker by ID than it is by searching for a string.
|
|
|
|
|
|
iam using vb.net2010 and phpmyadmin server onine ..
when i connect vb.net with phpmyadmin every thing work correctly with out any problem or warning..
but when i leave App (at running ) with out any action or event the problem rise
and tell me ("Fatal error encountered during command execution") ,
Note: the connection is open.
please help me
|
|
|
|
|
You will need to provide considerably more details than that. No one here can guess what your application is doing.
|
|
|
|
|
iam using vb.net2010 and phpmyadmin server onine ..
when i connect vb.net with phpmyadmin and execute query like this code
'--------------------
If mycon.State = ConnectionState.Closed Then
mycon.Open()
End If
Dim testid As Integer = 0
mydataAdapter = New MySqlDataAdapter("select ID from COMPANY order by ID DESC LIMIT 1", mycon)
mydataset = New DataSet
mydataAdapter.Fill(mydataset, "COMPANY")
If Me.BindingContext(mydataset, "COMPANY").Count > 0 Then
testid = mydataset.Tables("COMPANY").Rows(0).Item("ID")
End If
'------------------------------------------
...every thing work correctly with out any problem or warning..
but when i leave App (at running ) with out any action or event the problem rise
and tell me ("Fatal error encountered during command execution") ,
Note: the connection is open.
please help me
|
|
|
|
|
Unfortunately I am not familiar with any languages with a "V" in name...
Function zGetFolder( sFolder )
On Error Resume Next
Set zGetFolder = oFso.GetFolder( sFolder )
If Err.Number <> 0 Then
Wscript.Echo "Error connecting to: " & sFolder & VBlf & "[" & Err.Number & "]" & Err.Description
Wscript.Quit Err.Number
End If
End Function
Questions:
The line I don't understand is: Set zGetFolder = oFso.GetFolder(sFolder)
Why would you "Set" a call to oFso.GetFolder with "zGetFolder" the name of the function you are currently in???
I am also not quite sure what "On Error Resume Next" accomplishes with this construct.
|
|
|
|
|
In VBScript, if a function returns an instance of a class or any object, you have to SET the variable to that instance.
Also, "On Error Resume Next" is error handling, which would be a try/catch block in C#. Resume Next just tells VB to continue executing code even if an error occurs. It also sets the values of the Err object if an error does occur.
Basically, all that code boils down to this in C#:
var zGetFolder = new DirectoryInfo(sFolder);
You can find the documentation on the DirectoryInfo class here[^].
|
|
|
|
|
Thanks for the explanation. What you said makes perfect sense.
I still don't understand why you would do this:
Set zGetFolder = oFso.GetFolder( sFolder )
When zGetFolder is the name of the function that line of code is in.
Does this zGetFolder only exist in the scope of the function?
|
|
|
|
|
I think you'll find that the function is designed to return the folder to the calling method. Therefore
Steve Messer wrote: Set zGetFolder = oFso.GetFolder( sFolder ) should return the folder (it will be a variable in the calling function).
Never underestimate the power of human stupidity
RAH
|
|
|
|