The following code turns an image on or off based on whether there are two checkboxes checked. The problem is as I add checkboxes only the last two work correctly. In the example below the image does not turn on and off if chk_Pipe1N and chkIn1 are both checked. However it works perfectly when chk_Pipe2N and chkIn2 are both checked. If I add chk_Pipe3N and chkIn3 it will work for this set, but set 1 and 2 no longer work. Any ideas why?
'NIn
If Me.chk_Pipe1N Or Me.chk_Pipe2N And Me.chkIn1 Or Me.chkIn2 Then
Me.imgNIN.Visible = True
Else
Me.imgNIN.Visible = False
End If
'NOut
If Me.chk_Pipe1N Or Me.chk_Pipe2N And Me.chkOut1 Or Me.chkOut2 Then
Me.imgNOut.Visible = True
Else
Me.imgNOut.Visible = False
End If
Simpler (adding #HansUp's comment):
Me.imgNIN.Visible = (Me.chk_Pipe1N Or Me.chk_Pipe2N) And _
(Me.chkIn1 Or Me.chkIn2)
Related
i used to have some code that worked "kinda" ok for a stocktaking application. Where the user can scan a product and then enter the value of how many they have counted. i added the ability to be able to press the "+" key on the numpad and it would add the value that was already in the cell to the value you now entered in. so for example you counted 2 and then later you find more of the same product you now press + 5 and the cell would then show 7.
i had to use this stocktaking application today, and noticed the + function didnt work. when i looked at my code later tonight, there is no code there to handle the + and add the values. and for the life of me i cant remember how i got this working.
this is the code thats remaing so far.
STCellValue is a public integer value that stores the value already in the cell.
Private Sub DataGridView1_CellBeginEdit...
If Not IsDBNull(DataGridView1.Rows(rowindex).Cells("COUNTED").Value) Then
If STAddKeyPressed = True Then STCellValue =
CInt(DataGridView1.Rows(rowindex).Cells("COUNTED").Value)
ElseIf STAddKeyPressed = True Then
STCellValue = 0
End If
STAddKeyPressed is a boolean public value that is changed to true on the keydown event for the datagridview.
Private Sub DataGridView1_KeyDown(....
If e.KeyCode = Keys.Escape Then
'does things for escape key
ElseIf e.KeyCode = Keys.Add And FILE_Advanced_StocktakeMode.Checked = True Then
STAddKeyPressed = True
end if
i then have this code in the datagridview cellbeginedit subroutine.
If Not IsDBNull(DataGridView1.Rows(rowindex).Cells("COUNTED").Value) Then
If STAddKeyPressed = True Then STCellValue =
CInt(DataGridView1.Rows(rowindex).Cells("COUNTED").Value)
ElseIf STAddKeyPressed = True Then
STCellValue = 0
End If
End if
obviously this does nothing with the Value in the cell, nor does it add the two together, i played around with several things, but cant get it work.
i would have thought that in:
Private Sub DataGridView1_CellValueChanged
there would have been the code to handle the addition of the two values. but its not there.
at the moment if I press the + key on the numpad then a number, the cell will only record the number it will ignore the + and wont even leave it in the cell. so you don't end up with "+5" in the cell just "5". not sure how that's occurring to be honest.
like I said I did have this working in the past, but no idea why the code is now missing :/ I remember that it didn't always 100% of the time work the way it was intended but i didn't mind it was rare the issue would arise. I know im probably not going about the right way in handeling the key.down and events so if you can recommend a better way then im all ears!
I'm working with VBA, and I'm struggling to get a combobox with two options:
First option: the textbox next to it must appear one "-", like if is supposed to be empty or disabled.
Second option: the same texbox must must be able to receive an input, like numbers.
Like: "Do you have an ID?" if no, don't fill the texbox. If yes, fill it with your number.
Thanks!
I'm assuming C# implementation but this would work essentially for any .net or WINFORMS project.
if(cbo.selectedindex = 0)
tbFoo.text = "-";
else if(cbo.selectedindex == 1)
tbFoo.text = "filltextwithID";
Check if the selectedindex of your combobox is the first or second options in the list and do your first option with the first selectedindex, else if it is the second, fill your textbox with whatever you need to fill it with(textwise).
Use your conditional if statement(naturally, I know) to check your conditions that you want your combobox to do to your textbox.
Otherwise another way to do this is with a selectedindexchanged event and do your switch statement or if statement based on which selectedindex you are talking about. 0 is the first item....all the way up to n items.
I got it! Here's the code:
Private Sub ComboBox_Change()
If ComboBox = "I don't have an ID" Then
IdTextBox.Visible = False 'Hidden
IdLabel.Visible = False
Else
IdTextBox.Visible = True 'Unhidden
IdLabel.Visible = True
End If
End Sub
I have a list box and when there are no items in it I want the button to not be enabled. This is the code I have at the moment
If lstMarks.Items.Count = -1 Then
btnShowMean.Enabled = False
End If
However even when there is nothing in the list box you can still press the button. What is the best way to resolve this issue?
The count will never be less than zero:
If lstMarks.Items.Count = 0 Then
btnShowMean.Enabled = False
End If
or just:
btnShowMean.Enabled = (lstMarks.Items.Count > 0)
I am trying to create a VBA code that says, if combobox equals this or this or this then have radio button populate. When i use only one bucket (134) it works fine but when i try ti add multiple sections, i get and err.
My code:
If Me.cmbBucketFilter = "134,135,136" Then
'Working Echo Triggers
Me.fmeReached.Visible = True
Me.fmeRecovered.Visible = True
Me.fmeError.Visible = False
Else
'Working Another Bucket
Me.fmeError.Visible = True
Me.fmeReached.Visible = False
Me.fmeRecovered.Visible = False
End If
You're asking it to run only if cmbBucketFilter equals "134, 135, 136" (which it never can). What you really want is for it to run if it equals any of those values.
Change the first line to this:
If Me.cmbBucketFilter IN ("134", "135", "136") Then
How to get for null value in datagridview i did this in the cell validation event but it dosent seem to work. I want the user to add a new row and someone force him to give an ID or delete the row. What am i doing wrong. This is not a how to do question. This is a what is wrong Question. So right now it detects null but once i corrected the cell it still dosent allow me to get out of the row.
If DataGrid.CurrentCell.ColumnIndex = 0 Then
If IsDBNull(DataGrid.CurrentCell.Value) Then
Msgbox("Cannot be Null")
e.cancel = true
ElseIf Not IsDBNull(DataGrid.CurrentCell.Value) Then
e.cancel = False
End If
End If
So i tried this and it works for me . it simply uses e.formatedvalue. Current Cell Value is the cell value before and after edit while formatedvalue is what is being typed it . i guess i understand now so here is the coding
If grdDataGrid.CurrentCell.ColumnIndex = 2 Then
If e.FormattedValue = "" Or IsDBNull(e.FormattedValue) Then
MsgBox("Cannot be Null")
e.Cancel = True
Exit Sub
End If
End If
They are also different ways like adjusting your column properties to not allowed null but since the column properties inherit from the database i decided to use this.
I think this should be works ...
If DataGrid.CurrentCell.ColumnIndex = 0 Then
If IsDBNull(DataGrid.CurrentCell.Value) Then
Msgbox("Cannot be Null")
e.cancel = true
exit sub
End If
End If
Another way around this would be to explicitly set the default null value for the new datagrid cell to the value you are checking for. For instance,set the null= to an empty string if you are pulling string values. You can use the properties palette to set this.