If (dateDifference > 7 Or dateDifference < -7) Then
will trap dates outside of the 7 day range in either direction.
If (dateDifference > 7 Or dateDifference < -7) Then
will trap dates outside of the 7 day range in either direction.
Be aware that lost focus also fires when the app looses focus, not just when the control looses it. So, if the combobox has focus and they switch apps to read an incoming email, this event will fire.
The below code will trap the event you are after. However, once an item is selected, it can't be deselected without selecting another value. In other words, SelectedIndex will never again = -1. It would seem that you need to set Label26.visible = true during load and then let this function turn it off after the user selects a value.
Private Sub ComboType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboType.SelectedIndexChanged
If ComboType.SelectedIndex = -1 Then
Label26.Visible = True
Label26.ForeColor = Color.Red
Label26.Text = "(Select the Job Category )"
Else
Label26.Visible = False
End If
End Sub
I suggest that you create a new thread for this question as it has nothing to do with this thread and probably won't get answered here.
One more follow-up to this because I just spent a bunch of time fighting with this problem again. The controls that are being added must be visible = true at the time they are added. After they are added, they can be changed to visible = false if you don't want them shown yet. If they are visible = false when they are added, when they are set to visible = true for the first time, they are displayed in the wrong location.
That is what I have, however, this still allows part of the child window to go beyond the side of the container. In other words, can drag the child window so the upper left corner is at location (-100, 0) and end up with only the right half of the child window showing.
In my program, I want the user to be able to move an MDI child window anywhere inside the MDI container but I need it to be kept completely inside the container boundary. For example, the upper left corner should never be at a location less than 0,0 when moved left or up. Currently, if I slide the child window too far left, it extends outside of the MDI container window and the MDI container shows the bottom scroll bar.
Is there a way to prevent the child window from moving outside of the boundaries of the container window? I tried adding code to the .move (see below) so that if the new location was less than 0,0 then it reset it to 0,0 but then the child window controls flicker as the window is moved beyond 0,0 and the logic moves it back to 0,0. It appears that even though the code changes the location to 0,0 and the window shows the child moved to 0,0, when the mouse moves again, the window jump back to its unmoved location.
Private Sub MyForm_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
If Location.X < 0 Then
Location = New Point(0, Location.Y)
End If
If Location.Y < 0 Then
Location = New Point(Location.X, 0)
End If
End Sub
My apologies to adatapost. His/her answer sounded like he/she misunderstood my issue but the answer given was correct.
Here is the reason this happened. Because the child window did not have a font size assigned to the form, it was using the default font in Visual Studio. When it was added to the MDI container, it inherited the container's font which was larger than the child and increased the entire window (labels, textboxes, etc.) accordingly.
Here is the funny part. I originally said it was like it increased the child window by 10%. The child window was font 8.25 and the container was 9.0 which is a 9.09% increase.
Thanks adatpost for your answer and again, my apologies for jumping to the conclusion that you misunderstood my original post.
It's not just the font. EVERYTHING on the FamilyForm increases in size including the controls (labels, textboxes, etc.). It is like the entire FamilyForm increases by 10%.
I have a main form that has IsMdiContainer = true.
I have a second form (FamilyForm) that is to be the MDI child.
Using the code below, when the line TempForm.MdiParent = Me is executed, the FamilyForm window size, font, and all controls are larger than shown in Visual Studio, possibly 10% larger.
Dim TempForm As New FamilyForm(DataAccess, lvSearch.SelectedItems.Item(0).Text, lvSearch.SelectedItems.Item(0).SubItems(3).Text)
TempForm.MdiParent = Me
TempForm.Name = lvSearch.SelectedItems.Item(0).Text
TempForm.Show()
However, if i remove the line TempForm.MdiParent = Me (no other changes were made), then FamilyForm exactly matches what I see in Visual Studio.
Can anyone tell me what is causing the FamilyForm size to increase when the parent is assigned?
I'm not sure what you are trying to do but try changing it to
Array.Reverse(arrFilename)
After a whole lot of research, I finally found the answer. Replace the btnAdd_Click subroutine with the following.
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim OnTheFlyButton = New Button
OnTheFlyButton.Location = New Point(10, 100 [B][I][U]+ Panel1.AutoScrollPosition.Y[/U][/I][/B])
OnTheFlyButton.Name = "Button" & ButtonCount.ToString
OnTheFlyButton.Text = "Button " & ButtonCount.ToString
Panel1.Controls.Add(OnTheFlyButton)
OnTheFlyButton.BringToFront()
ButtonCount += 1
End Sub
By including Panel1.AutoScrollPosition.Y in the Y location calculation, it adjusts the location of the new button based on where Panel1 is currently scrolled.
Remember that a "do while" loop executes the logic inside the loop and then executes the while. In your case, you are trying to do an rs.getString(1) but have never done the rs.next to load the values.
Your code should look like this
<%
while(rs.next)
{
user = rs.getString(1);
pass = rs.getString(2);
typ = rs.getString(3);
%>
pnt = user + " " +pass+" "+typ;
%>
<p> <%=pnt%> </p>
<%
}; <== Not sure if you need the ";". I forget the syntax for the end of a while loop.
%>
If this still blows up, please repost your code and tell exactly what line is blowing up.
It has been a while so I could be remembering this incorrectly.
I believe you need to do your rs.next() before your rs.getstring(). The execute query does not retrieve any data from the database, only prepares it for the first rs.next(). By having a do...while, your while is not executed until the end of the do loop.
Try changing your
do
{
}while rs.next()
to
while rs.next()
{
}
Let me know if that doesn't fix the problem.
Your SQL statement is messed up. Where clauses need "AND"s between comparisons, not commas.
'12345' = CustomerID AND 'Smith' = Surname
Run this in the debugger and break on line 130 (based on the above code) and look at SQLString. Also, before you have problems with it later, your SQLString built in line 82 is wrong too. Select where clauses also need "AND"s between comparisons, not commas.
You've missed my point. The code that I posted should stack them on top of each other but it does not if the panel has been scrolled down. I need this code to stack them on top of each other regardless of where the panel is scrolled to. When the first button is placed at 10,100 and then you scroll the panel 25 points, the second button is actually placed at (10,125) instead of (10,100). Scroll again another 25 points and add a button at (10,100) and it is actually added at (10,150). Based on what the sample program is doing, to stack a second button directly on top of the first, I would have to place it at (10, 75) or (10, DesiredPosition - ScrollPosition).
The logic in my real program is adding a control at (10,100) and then later attempts to add another control at (10,130). However, because the panel has been scrolled down, it actually adds it at (10,200).
I'm not sure when you are trying to total so here are two possible ways.
Create a variable named Total
Dim Total as Double
To keep a running total as things are entered...
After adding the info to the listboxes...
QuantityList.Items.Add(quantity)
MenuitemList.Items.Add(item)
PriceList.Items.Add(price)
Total += quantity * price
To total everything in the listboxes...
For x = 0 To PriceList.Items.Count - 1
Total += Val(PriceList.Items(x)) * Val(QuantityList.Items(x))
Next
If that doesn't answer your question, please post more details.
I have a program that adds controls on the fly to an auto-scroll panel. When the panel is scrolled (viewing the bottom of the panel for example) and a control is added, it looks like it is added assuming the top left corner of the panel is still at 0,0 when in fact it may be 0,500. To see what I am talking about, create an empty "Windows Forms Application" project and insert the below code into it.
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents btnAdd As System.Windows.Forms.Button
Dim ButtonCount As Integer
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim OnTheFlyButton = New Button
OnTheFlyButton.Location = New Point(10, 100)
OnTheFlyButton.Name = "Button" & ButtonCount.ToString
OnTheFlyButton.Text = "Button " & ButtonCount.ToString
Panel1.Controls.Add(OnTheFlyButton)
OnTheFlyButton.BringToFront()
ButtonCount += 1
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Panel1 = New System.Windows.Forms.Panel
Me.btnAdd = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Location = New System.Drawing.Point(0, 57)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(200, 100)
Me.Panel1.TabIndex = 0
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(4, 28)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(75, 23)
Me.btnAdd.TabIndex = 5
Me.btnAdd.Text = "Add"
Me.btnAdd.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(300, 200)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.Panel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Now run the app and click the Add button. Scroll the panel down and you will see where it …
You have a <BR> between each of your table row end tags and the next table row start tags.
</TR>
<BR>
</TR>
Because the <br> is not in a table row, the browser moves it outside of the <table>. If you want a blank line, add a <br> after the text.
<font color="#BD2031" face="Bradley Hand ITC" size="4"><b>I like : To smile :-)</b><br>
You also need to remove the <br> from between the </head> and <body> tags and the one before the </tbody> tag. They are also being added above the table.
Also,
<center><font color="#BD2031" face="algerian" size="6">!! I LIKE - I HATE !!</center>
should not be in the <HEAD> section, it should be in the <BODY> section.
Thanks for the explanation and the workaround. That is what it looked like it was doing but didn't make sense. Someone should tell Microsoft that a "for each" should take a snapshot and process the snapshot.
When you do a for each and remove controls from the collection you're iterating over, it creates problems like the one you're having.
Say if you have a list like
item1
item2
item3You do a for each loop over the collection and remove the first record and then move to the second. With item1 gone, item2 is now the first record, and item3 is the second! The next candidate for removal is therefore not item2, but the new second record of item3.
Instead, consider doing a for loop and going in reverse order, and then remove items at specifix indexes.
Dim controlIndex As Integer = Panel1.Controls.Count - 1 For index As Integer = controlIndex To 0 Step -1 Panel1.Controls(index).Dispose() Next
By removing items starting at the end, you're not affecting the order or position of the elements at the beginning and your removal process should work as you intend as you go backwards over the collection.
I'm not sure from your post if you still have questions. One thing that looks like you may still be confused is the .dispose and .add. .dispose deletes the control from your program and frees the memory. The only way to do the .add is to recreate the control.
If you still have questions, post a little more detail about your program. Are you manually creating and adding controls to your forms or are they controls created via drag and drop using the GUI? Why are you trying to take them off of the form?
What do mean by "does not load"?
Control Events > Load. Since you told me that .remove does not delete the control, more than enough answer for me.-----
Whenever I .Add a control after I .Dispose it, I receive a message "can't access a disposed object"
My program deletes a control and adds it again. I don't want to use .Remove because it requires me to manually reload all variables.
I wanted to delete all of the TextBoxes that I put on a form that start with "tbx". The below code only deleted some of them.
For Each ctl As Control In Panel1.Controls
If ctl.Name.StartsWith("tbx") Then
ctl.Dispose()
End If
Next
So, I took it a step further in testing...
Now I'm really confused about the .controls collection. When I try to delete controls from Panel1 with the below code, it only deletes every other control instead of all controls.
For Each ctl As Control In Panel1.Controls
ctl.Dispose()
Next
It looks like it deletes item(0) which moves everything back one step but then advances the pointer to the next step.
For example, if the following controls exist on the form...
tbx1
tbx2
tbx3
tbx4
on the first pass it disposes of tbx1 but the next iteration though the for each loop now points to tbx3, thus bypasssing tbx2.
Any explanation on why this is doing this and how to get around it?
Assuming you are using a SaveFileDialog, try .InitialDirectory = "yourpath"
how to set destination directory path to save file
.Remove does not delete or alter the control, it just takes it off of Form1.
.Dispose removes the control from Form1 and deletes it.
.Add adds the control to Form1 AS IS.
I'm not sure what you mean by "does not load" and what variables are not reloaded. Give me a little more detail on that part and I will try to point you in the right direction.
Can anyone tell my why the code...
Form1.Controls.Remove(myCustomControl)
...does not remove the control.
Because whenever I remove a control and add it again, it does not Load but rather just changes its visibility from false to true and all the variables are not reloaded.
I tried to use .Dispose() but VB.net tells me that it can't access a disposed object whenever I try to add the control again.
Any better methods?
I'm curious as to which line of your code is blowing up and what the exact error is because this should work. I use this logic all of the time.
Also, don't forget to handle if the user puts single quotes in their answer such as a username of O'Brien. I handle this by using .replace as in
kueri = "select Username, Pass, Nama, SecQue, SecAns from Account where Username = '" + TextBox8.Text.Replace("'", "''") + "'"
which replaces any single quote with two single quotes.
Since rd.read() will return a true if the read was successful and false if it was not, try...
If rd.read() Then
If TextBox8.Text = rd(0) Then
...remainder of your code
End If
Else
MsgBox("BAD Username")
End If
From the code posted, I think you are trying to update the record you previously read, correct? If so, the syntax you need is something like:
UPDATE MathsTest
SET EasyTime = @EasyTime, EasyDate = @EasyDate
WHERE LoginName = '@Username' AND Password= '@Password'
and don't forget to also pass the Username and Password.
This also assumes there is only one row for the Username / Password. If there are multiple rows (as in multiple tests) then you will probably need to add additional criteria to the where clause to specify which row (test) to update.
There is also a way to specify on the select that it is for update but that is a little beyond my knowledge (and not sure if it works in Access). I always specify the where clause when I do updates just in case I read another record and forgot.
Without seeing code, I'm flying blind but here are a few possibilities.
1) Is the query that does not work not passing all parms?
2) Is the value for Param4 not a string? This should give a different error but it's a guess.
Post a little code and maybe I can help you figure something out.
I have a program that allows the user to add steps to a process (tabpages in a control). All tabpages are generated on the fly by duplicating a "template" tabpage and consequently have the same control names such as textboxStepDesc. Here is the hierarchy of the controls to get to textboxStepDesc. Both TabPage1 and TabPage2 are in TabControl1
TabPage1
Panel1
textboxStepDesc
other fields
TabPage2
Panel1
textboxStepDesc
other fields
Since textboxStepDesc exists in Panel1 in both TabPage1 and TabPage2, how do I specify that I want to retrieve the value of textboxStepDesc.text on tabpage2 vs. textboxStepDesc.text on tabpage1?