I populate DataGridView with data and depending on the data I put an image in the 12th column either succes or fail. My goal is to be able to double-click on the 12th cell and show MsgBox with the status inside. I can pretty much do all whats was asked in the homework. However I can't tell in IF CONDITION; if the image in the 12th row = to succes;
here's the error;System.InvalidCastException : 'L'oerator '=' not defined for type 'Bitmap' and type 'Bitmap'.'
thank you for all the help
Private Sub DgvTest_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvTest.CellMouseDoubleClick
If e.ColumnIndex = 12 And dgvTest.Rows(e.RowIndex).Cells("status").Value = imgList.Images.Item("fail") Then
Dim numTest As String = dgvTest.Rows(e.RowIndex).Cells.Item(0).Value
For Each i As Test_Auto In lst_Test_Auto
If i.No_Test = numTest Then
If i.status = False Then
MsgBox("status of test #" & numTest & " ; " & "a generated and error: " & i.message)
End If
End If
Next
End If
End Sub
Related
I'm kinda new to MS Access and I'm sort of learning while coding, so forgive me if my question is a bit weird.
I have created a form based on a table, and in the form I have a text box that the user would type something and it should filter the table and show the results based on what the user typed. There are two forms with pretty much the same code on them (named Rec and Cx). In one of them (Rec) the above description works just fine, but the other (Cx) don't and I get a run-time error 2185. Let me show you some code:
Private Sub strConsRecDesc_KeyUp(KeyCode As Integer, Shift As Integer)
FiltroRec = ""
FilterTextDesc = ""
If Len("" & Me.strConsRecDesc.Text) > 0 Then
intLenDesc = Len(Me.strConsRecDesc.Text)
RequeryForm
strConsRecDesc.SetFocus
Me.FilterOn = True
If intLenDesc > Len(Me.strConsRecDesc.Text) Then
Me.strConsRecDesc = Me.strConsRecDesc & " "
Else
Me.strConsRecDesc = FilterTextDesc
End If
strConsRecDesc.SelStart = intLenDesc
Else
RequeryForm
strConsRecDesc.SetFocus
End If
End Sub
I heard it is good practice to lable variables and fields based on data type, so here int stands for integer, str for strings and Desc refers to the Description field.
Based on what is typed in the field strConsRecDesc I filter the table using the RequeryForm in there, that basically checks all the fields in the form that the user can write into. Let me show you the part for the description field:
strConsRecDesc.SetFocus
If Len(strConsRecDesc.Value) > 0 Then
FilterTextDesc = Me!strConsRecDesc.Value
If Len(FiltroRec) > 0 Then
FiltroRec = FiltroRec & " And "
End If
FiltroRec = FiltroRec & "[recDescricao] LIKE '*" & FilterTextDesc & "*'"
End If
In this form (Rec), I can write, i.e. this is a test and no record is shown, because there is no record with this is a test written in it, and that is correct. If I type something that matches the criteria it works just fine.
However, in the other form (the Cx one), I have the following code for KeyUp:
Private Sub strConsCxDesc_KeyUp(KeyCode As Integer, Shift As Integer)
FiltroCx = ""
FilterTextDesc = ""
If Len("" & Me.strConsCxDesc.Text) > 0 Then
intLenDesc = Len(Me.strConsCxDesc.Text)
RequeryForm
strConsCxDesc.SetFocus
Me.FilterOn = True
If intLenDesc > Len(Me.strConsCxDesc.Text) Then
Me.strConsCxDesc = Me.strConsCxDesc & " "
Else
Me.strConsCxDesc = FilterTextDesc
End If
strConsCxDesc.SelStart = intLenDesc
Else
RequeryForm
strConsCxDesc.SetFocus
End If
End Sub
And the equivalent RequeryForm for the Cx is:
strConsCxDesc.SetFocus
If Len(strConsCxDesc.Value) > 0 Then
FilterTextDesc = Me!strConsCxDesc.Value
If Len(FiltroCx) > 0 Then
FiltroCx = FiltroCx & " And "
End If
FiltroCx = FiltroCx & "[cxDescricao] LIKE '*" & FilterTextDesc & "*'"
End If
But in the Cx one if I type this is a test in the strConsCxDesc textbox I get a run-time error 2185.
I understand that with just this bit of code it is kinda hard to grasp what I'm trying to do, but I really don't know why I'm getting this error if the code is the same.
I appreciate any help, and I'm sorry for my bad english, it's not my mother language.
Thanks in advance.
I am trying to retrieve a surfer from a list on a textfile, the user selects the surfer from the combo box which then displays that surfers data in a bunch of labels. My code requires each surfer to have an ID for it to be able to know which record to retrieve from the database. However when I try to put my ID from my loop together with each surfers name, I receive an error saying "Conversion from string to type 'Long' is not valid." I have tried different methods of getting around this, none of which have worked. Here is my code:
Private Sub Lookup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
madelabel = False
For i = 1 To maxrecJudge
FileGet(2, ajudge, i)
recnoJudge = i
judgename = recnoJudge And " " And ajudge.name
cmbJudge.Items.Add(judgename)
Next i
For i = 1 To maxrecSurfer
FileGet(1, asurfer, i)
recnoSurfer = i
surfername = recnoSurfer And " " And asurfer.name
cmbSurfer.Items.Add(surfername)
Next i
End Sub
Private Sub cmbSurfer_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbSurfer.SelectedIndexChanged
recnoSurfer = CInt(Val(New Text.StringBuilder((From ch In cmbSurfer.Text.ToCharArray Where IsNumeric(ch)).ToArray).ToString))
FileGet(1, asurfer, recnoSurfer)
If madelabel = False Then
lblName = New Label
lblName.Top = 160
lblName.Left = 253
lblName.Autosize = True
lblName.Text = asurfer.name
Me.Controls.Add(lblName)
End Sub
For simplicity I have only included one label creation above, but there are several labels spawned each with data of the surfer.
Am I on the right track with this? In the second sub my code extracts the integer (ID) from the combo box which then is used as a record number to find the rest of the data. The error relates to these lines:
surfername = recnoSurfer And " " And asurfer.name
cmbSurfer.Items.Add(surfername)
It won't let me concatenate the ID and the surfers name. Any help?
If you are doing a lot of concatenation, use a StringBuilder. It is far quicker. Every time you concatenation strings, a new string is created. Over a large amount of iterations, StringBuilder is the better choice.
Good Day to everybody.
I ran out of ideas so I'm posting this to SO, I want to create a form where users can search for records, then tik check on the datagrid view, then retain the check even though they used.
In this illustration the user searched for a certain number then selected it, its the bottom one.
I would want it that if the user would like to search for another record, the item wont be removed.
in this illustration, the item was removed because the use searched for another record.
My current work is the following
Private Sub dgvConfirm_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvConfirm.CellContentClick
If dgvConfirm.Item(0, dgvConfirm.CurrentRow.Index).Value = 0 Then
dgvConfirm.Item(0, dgvConfirm.CurrentRow.Index).Value = 1
nmblst = nmblst + dgvConfirm.Item(2, dgvConfirm.CurrentRow.Index).Value + ","
Else
dgvConfirm.Item(0, dgvConfirm.CurrentRow.Index).Value = 0
End If
End Sub
this is the code when I clicked the datagridview, it just gets the unique key column and transfers it into a string.
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
If nmblst <> "" Or nmblst.Length > 0 Then
nmblst = nmblst.Trim().Remove(nmblst.Length - 1)
scndQry = " or PPFNo in ('%" & nmblst & "%') "
End If
If rdoPartNo.Checked = True Then
bndsrc.Filter = "PartNo Like '%" & txtSearch.Text & "%' " + scndQry
Else
bndsrc.Filter = "PPFNo Like '%" & txtSearch.Text & "%' " + scndQry
End If
frstQry = bndsrc.Filter
End Sub
This code is for searching. I am trying to use something like select this from thistable where columnname like '%something%' and columname in (etc,etc) do take note that columnname and columnname are the same.
Is there a property of datagridview for what I need?
I think that you are approaching this problem incorrectly.
Assuming that only one item can be checked, try storing the checked row in a type, with each column stored separately, like this:
Private Type temp
PartNo As Long
PPFNo As Integer
ProductNo As String
DateCreated As DateTime
And so on...
End Type
When something is checked, you find the row on which the box is checked, and then you put each field in the temp type, something like this:
For i = 0 to DataGridView.Columns - 1
temp(i) = DataGridView.Item(i, selectedrow).Value
Loop
Then, at the end of your search, you can append your temp to the DataGridView by adding the following to your code:
DataGridView.Rows.Add(temp(0),temp(1),temp(2),temp(3)) 'And more if you have more columns
Good luck with your problem and I hope my answer helps :)
I am using MS SQL Server and Visual Basic.
I want to combine a calculated column and another column to add units to the calculation. (for example "200 m2")
DgwNewLayout.Columns(5).DefaultCellStyle.Format = "0.00 " & "'" & DgwNewLayout.CurrentRow.Cells(9).Value & "'"
This code does that but only for first entered unit? How can I do this for each column?
You could use CellFormatting event.
Private WithEvents DgwNewLayout As DataGridView
Private Sub DgwNewLayout_CellFormatting(sender As Object,
e As DataGridViewCellFormattingEventArgs
) Handles DgwNewLayout.CellFormatting
If e.ColumnIndex = 5 Then
e.Value = CDbl(e.Value).ToString("0.00") &
" " & CStr(DgwNewLayout.Rows(e.RowIndex).Cells(9).Value)
e.FormattingApplied = True
End If
End Sub
As Dom Sinclair says, this could have poor performance.
I have two datetime pickers in vb.net that calculate the number of days between two dates and display in a message box the number of days. I want the number to display in a text box using vbnewline or any method but NOT to display in a messageBox
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs)Handles btnCalculate.Click
If True Then
Dim dt1 As DateTime = Convert.ToDateTime(DateTimePicker1.Text)
Dim dt2 As DateTime = Convert.ToDateTime(DateTimePicker2.Text)
Dim ts As TimeSpan = dt2.Subtract(dt1)
If Convert.ToInt32(ts.Days) >= 0 Then
MessageBox.Show("Total Days are " & Convert.ToInt32(ts.Days))
Else
MessageBox.Show("Invalid Input")
End If
End If
End Sub
Any input appreciated
Why not simply use Environment.NewLine
TextBox1.Text = "Total Days are"
TextBox1.AppendText(Environment.NewLine & Convert.ToInt32(ts.Days))
I think you are a bit confused. You can show the info in a TextBox, a MessageBox or a Label, but vbNewLine is just a constant that represents a line break, so you can use it with any of the previous controls.
Just put a TextBox usign the designer and then change the line
MessageBox.Show("Total Days are " & Convert.ToInt32(ts.Days))
with this:
YourTextBox.Text = "Total ......"
Good luck but do a little research the next time.