|
I have a simple WinForms application with data displayed in a property grid.
Now i am trying to make the application a little more user friendly for a touch screen operation.
I have added simple user control with buttons to simulate a virtual numeric keyboard. The problem is that as soon as i press the buttons on the usercontrol the PropertyValueChanged fires even though the PropertyGrid.ContainsFocus still is true.
This is causing a problem because the input is not yet ready and may still be under/over limit causing the property grid to revert back to its old value.
First i thought it was a problem with the user control stealing focus so i added the following code that i found i a forum to the buttons but the event still fires.
Friend Class UnselectableButton
Inherits Button
' The WS_EX_NOACTIVATE value for dwExStyle prevents foreground
' activation by the system.
Private Const WS_EX_NOACTIVATE As Long = &H8000000L
''' <summary>
''' Set the form style to WS_EX_NOACTIVATE so that it will not get focus.
''' </summary>
Protected Overrides ReadOnly Property CreateParams() As CreateParams
<PermissionSet(SecurityAction.LinkDemand, Name:="FullTrust")>
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or CInt(Fix(WS_EX_NOACTIVATE))
Return cp
End Get
End Property
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.Selectable, False)
End Sub
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'UnselectableButton
'
Me.TabStop = False
Me.ResumeLayout(False)
End Sub
End Class
Does anyone know how to suppress PropertyValueChanged or any other way around the problem.
|
|
|
|
|
|
gostaria de ciar o id auto_increment e da erro .
me ajude por favor
Sub criatabelaconfiguracoes()
Try
Dim conn As MySqlConnection
Dim strConn As String
Dim cmd As MySqlCommand
strConn = "Server ='" & txtServer.Text & "'; userid = '" & txtUser.Text & "'; password = '" & txtSenha.Text & "';"
'strConn &= "Database = mysql; pooling=false;"
conn = New MySqlConnection(strConn)
cmd = New MySqlCommand("Create Database If Not exists habitacao", conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.ChangeDatabase("habitacao")
Dim sbCmd As New System.Text.StringBuilder
sbCmd.Append("CREATE TABLE configuracoes")
sbCmd.Append("(id INT(10)," & _
"tempolog varchar(255)," & _
"nomesistema varchar(255)," & _
"impressora varchar(255))")
cmd = New MySqlCommand(sbCmd.ToString, conn)
cmd.ExecuteNonQuery()
conn.Close()
criatabelausuario()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
|
|
|
|
|
You have been a member long enough to know that this is an English language site.
Use the best guess
|
|
|
|
|
That's not a problem related to Visual Basic, but to MySQL!
Hint: id INT(10) creates a "normal" numeric column, without autoincrement. I do not know the MySQL specific syntax for that, the documentation will tell you.
|
|
|
|
|
how to make calculator? in vb.net
|
|
|
|
|
Probably by creating a Windows Forms application. Google can probably find you many samples that will help.
Use the best guess
|
|
|
|
|
<pre lang="vb"><pre lang="vb"><pre lang="vb"> Hi you can check the below code to create a simple calculator with 4 functionalities.
Public Class frmcalculator
Dim Operand1 As Double
Dim Operand2 As Double
Dim [Operator] As String
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, Button2.Click
txtsource.Text = txtsource.Text & sender.text
End Sub
Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
txtsource.Text = ""
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = ""
txtsource.Focus()
[Operator] = "+"
End Sub
Private Sub btndecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If InStr(txtsource.Text, ".") > 0 Then
Exit Sub
Else
txtsource.Text = txtsource.Text & "."
End If
End Sub
Private Sub btnequals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Result As Double
Operand2 = Val(txtsource.Text)
Select Case [Operator]
Case "+"
Result = Operand1 + Operand2
MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
txtsource.Text = Result.ToString("#,###.00")
Case "-"
Result = Operand1 - Operand2
MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
txtsource.Text = Result.ToString("#,###.00")
Case "/"
Result = Operand1 / Operand2
MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
txtsource.Text = Result.ToString("#,###.00")
Case "*"
Result = Operand1 * Operand2
MsgBox(Result.ToString("#,###.00"), MsgBoxStyle.Information, "Result")
txtsource.Text = Result.ToString("#,###.00")
End Select
txtsource.Text = Result.ToString("#,###.00")
End Sub
Private Sub btnminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnminus.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = ""
txtsource.Focus()
[Operator] = "-"
End Sub
Private Sub btnmultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmultiply.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = ""
txtsource.Focus()
[Operator] = "*"
End Sub
Private Sub btndivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndivide.Click
Operand1 = Val(txtsource.Text)
txtsource.Text = ""
txtsource.Focus()
[Operator] = "/"
End Sub
Private Sub btnaddminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
txtsource.Text = -1 * txtsource.Text
End Sub
Private Sub btnx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnx.Click
Dim convert As Single
If txtsource.Text <> 0 Then
convert = 1 / Val(txtsource.Text)
txtsource.Text = convert
End If
End Sub
Private Sub frmcalculator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Call btnequals_Click(sender, e)
End If
End Sub
Private Sub frmcalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
End Class
|
|
|
|
|
Try something and then post issues here.
|
|
|
|
|
I really need help with this.
1. I have a excel file with columns with text and some with only the date in it (07/16/2013). This date can be in more than one row.
2. I then have a form where I can display all the info in the form (Eg like if I choose server, it will show me that server info on the form with all the other details that goes with it.
I get the info form my excel file.
3. I then have a button to search for info eg Server names, it then make a data grid view and show my all the servers that start with eg. Prasa.
4. Now my problem is I cannot get it to search for a date. I need help with this.
Here is my main code and my button date search code.
Is the a sample of this or can someone help me with this.
Imports System.Data.OleDb
Public Class Tapes_info
Private dtGlobal As New DataTable
Private Sub Tapes_info_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dtGlobal.Clear()
Using cn As New OleDb.OleDbConnection
Dim Builder As New OleDbConnectionStringBuilder With {.DataSource = IO.Path.Combine(Application.StartupPath, "Backuptapes.xls"), .Provider = "Microsoft.ACE.OLEDB.12.0"}
Builder.Add("Extended Properties", "Excel 12.0; IMEX=1;HDR=No;")
cn.ConnectionString = Builder.ConnectionString
cn.Open()
Using cmd As OleDbCommand = New OleDbCommand With {.Connection = cn}
cmd.CommandText = "SELECT TOP 5130 F1 As Tapes, F2 As Containere, F3 as ContainerRef, F4 as DateOut FROM [Tapese$]"
Dim dr As System.Data.IDataReader = cmd.ExecuteReader
dtGlobal.Load(dr)
LstTape.DisplayMember = "Tapes"
LstTape.DataSource = dtGlobal
txtContainer.DataBindings.Add("Text", dtGlobal, "Containere")
txtContainerRef.DataBindings.Add("Text", dtGlobal, "ContainerRef")
txtDateOut.DataBindings.Add("Text", dtGlobal, "Dateout")
End Using
End Using
End Sub
Private Sub BtnSearchDateOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearchDateOut.Click
For i As Integer = 0 To dtGlobal.Rows.Count - 1
If IsDBNull(dtGlobal.Rows(i)("Dateout")) Then
dtGlobal.Rows(i)("Dateout") = ""
End If
Next
Dim query = From item In dtGlobal.AsEnumerable() Where item.Field(Of String)("Dateout").StartsWith(txtSearchDateOut.Text) Select item
If query.Count > 0 Then
Dim newDT As DataTable = query.CopyToDataTable()
MsgBox(newDT.Rows.Count.ToString() & " Date out found.")
Dim frm As New Form()
Dim dgv As New DataGridView()
dgv.DataSource = newDT
dgv.Refresh()
frm.Controls.Add(dgv)
dgv.Dock = DockStyle.Fill
frm.Size = New Size(1400, 700)
frm.Show()
Else
MsgBox("There is no Date for this found.")
End If
|
|
|
|
|
2 main issues, using excel as a data store (probably not going to change) and the main issue is that you are storing your dates as string/text. ALWAYS use the date or datetime data type for storing and manipulating date.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: you are storing your dates as string/text I've lost count of the number of questions with that 'feature'. I wonder who is teaching these people?
Use the best guess
|
|
|
|
|
To be honest I don't think anyone is teaching them, I remember when I was learning I stored dates as text, I then discovered the data type, that was in the 80s mind you. If these people are just diving in to build some hobby app without ever having done any reading I would expect these questions.
The seriously frightening thing is they may have been taught!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes I do not have any training in vb.net. I am trying to lean it on my own, as the courses here in south Africa is very expensive.
Where must the date be not string/text, I don’t understand where I should change it.
|
|
|
|
|
I have a web-server and my database is MySQL in Xampp so I want to use VB 2008 to connect MySQL in XAMPP 1.7 by internet online ..help me please
|
|
|
|
|
manoph wrote: I have a web-server and my database is MySQL in Xampp so I want to use VB 2008 to connect MySQL in XAMPP 1.7 by internet online I assume that you're talking about an ASP.NET application, not a WinForm app. Wouldn't XAMPP be more suited for PHP-development, as opposed to hosting ASP.NET apps?
You'll need a webserver that's capable of serving ASP.NET pages; those will connect to the MySQL in your XAMPP stack. The webserver needs to be accessible from outside of the network; meaning that you'll need to setup your firewall and router to accept incoming traffic. If you're doing this on an ADSL-line from home, look at the NAT-settings of the router.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks you for your advise
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi,
I am trying to generate a report with Crystal Report.
But my report is blank
My code is ...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
OpenConnection()
qry = "SELECT * FROM customer"
dbcommand.Connection = DbConn.conn
dbcommand.CommandText = qry
dbadapter.SelectCommand = dbcommand
dbadapter.Fill(stdata, "Customer")
Dim objRpt As New CustomerRpt
objRpt.SetDataSource(stdata.Tables("Customer"))
rptViewer.ReportSource = objRpt
rptViewer.RefreshReport()
Catch ex As Exception
MsgBox(ex.Message)
Finally
CloseConnection()
End Try
End Sub
The Customer table has 7 rows.
I am using mysql database and vb.net 2010.
One more thing I would like to inform you that, while designing the CrystalReport, I did not find any field in CrystalReport --> Field Explorer --> Database fields
|
|
|
|
|
Put a breakpoint and then examine stdata.Tables right after you call fill.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have created a class which when instantiated, creates a SQL connection, SQL command, etc.
By repeatedly calling some methods it processes data using that one connection and SQL command.
When I'm done with this object, shouldn't I close/dispose of my SQL connection and command?
Should I do this by implementing Dispose() ?
Or
Should I create a method within my class called,"CleanUp" and just release the SQL connection and command there.
Also, I have a few Dictionaries and Lists in this class; should I ".Clear" them also ?
Maybe I should just set "myObject = Nothing" in my calling application?
Your guidance is appreciated.
|
|
|
|
|
If your class owns references to disposable objects, it should implement IDisposable to dispose of those references.
Providing a public method with a different name has no benefit; you won't be able to wrap your class in a Using block, and developers using your class might not even realise that they have to call your SpecialSnowflakeCleanUp method when they've finished with an instance of your class. If your class implements IDispoable , it's a clear indication that it requires clean-up.
There's no need to clear collections or references to managed objects; you only need to worry about unmanaged references and disposable objects.
Implementing IDisposable and the Dispose Pattern Properly[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hmmm ... Based on your suggestions, I am going to refactory my code.
|
|
|
|
|
Hello All,
I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self.
Example: When I drag Label1 it will leave another Label to its Original Position( Lets Name the New Label1 in Original Position as Label2),
Then I should also be able to drag Label2 and Leave another Label (Label3), I also want to drag Label1 and Label2 but it should not leave a copy.
Here is my code: I been able to do multiplication of Label and Dragging of Label but I cannot drag all Labels:
Public Class Form1
Dim cursorX, cursorY As Integer
Dim dragging As Boolean
Dim labelno As Integer = 1
Private Sub Control_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
dragging = True
cursorX = e.X
cursorY = e.Y
Dim label2 As New Label
labelno += 1
label2.Location = New Point(Label1.Location.X, Label1.Location.Y)
label2.Name = "Label" + labelno.ToString
label2.Text = label2.Location.ToString
Me.Controls.Add(label2)
End Sub
Private Sub Control_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
dragging = False
End Sub
Private Sub control_MouseMOve(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If dragging Then
Dim ctrl As Control = CType(sender, Control)
ctrl.Left = (ctrl.Left + e.X) - cursorX
ctrl.Top = (ctrl.Top + e.Y) - cursorY
ctrl.BringToFront()
End If
End Sub
If you have clarification please inform me.
Thanks
|
|
|
|
|
You don't put the dragging code for a Label in the Form. You create your own Label control and put the dragging code in there. That makes your Label reusable in any control that has a Controls collection, such as a Form or Panel or whatnot.
I wrote up an article to do this very thing about 7 years ago and it's still valid today. Read: Create your Own Runtime Movable Windows Forms Controls[^]
|
|
|
|
|