There is no direct access to disable column sorting in the datagridview.
But you can try this:
For Each dgvCol As DataGridViewColumn In Me.DataGridView1.Columns
dgvCol.SortMode = DataGridViewColumnSortMode.NotSortable
Next
There is no direct access to disable column sorting in the datagridview.
But you can try this:
For Each dgvCol As DataGridViewColumn In Me.DataGridView1.Columns
dgvCol.SortMode = DataGridViewColumnSortMode.NotSortable
Next
Assuming that your text is in a RichTextBox control.
Try this:
Public Class Form1
Private WithEvents prn As Printing.PrintDocument
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form1.Load
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
prn.Print()
End Sub
Private Sub prn_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles prn.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim printFont As Font = Me.Font
Dim myBrush As New SolidBrush(Color.Black)
Dim text() As String = RichTextBox1.Lines
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
Try
For i As Integer = 0 To text.Length - 1
If count < linesPerPage Then
yPosition = topMargin + (count * printFont.GetHeight(e.Graphics))
e.Graphics.DrawString(text(i), printFont, myBrush, leftMargin, yPosition, New StringFormat())
count += 1
Else
Exit For
End If
Next
Catch ex As Exception
End Try
'This is needed
e.HasMorePages = True
e.HasMorePages = False
myBrushes = Nothing
End Sub
End Class
There is no easy way to achieve this.
But the newest version of this third-party component has functionality for it.
http://www.ocrtools.com/fi/Default.aspx
Weird, is what it is.
Did you put "outage_summary" as table name in both "SELECT ...." querys?
You should put the name of the table as it appears in the access database.
And use the same name for the other SQL query as well.
No, switching access version would have no impact on this.
I just noticed something.
What happens if you add a space between Data and Source in the connection string.
Ie, change from "DataSource" to "Data Source".
No. It has nothing to do with the server version.
And I was just making sure of the Access version.
There's obviously something hinky with the connection string.
If everything is as it should be, your connection string should look something like this, (where C:\mydatabase.mdb is YOUR path and database file):
Dim accConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
Oooh, I just realized.
Try changing from JET to Jet in the connection string.
It's a small chance, but let's try it anyway.
Ok.
On what line in the method PerformImportToSql does this error occur?
And what version of Access database are you trying to read? x<=2003 or 2007?
One of the most likely causes for that ISAM error is that you may be missing the JET 4.0 data access component.
It's available for download from this link.
And as for your other question.
And yes, you need to change <tablename> into the name of the table in the database.
Good luck! :)
At what time does this error occur, and what does the code look like where the error occurs?
Have you set this second form as the startup form from within the project properties?
You're welcome. :)
Please mark the thread as solved if this has been helpful.
On what line is the error thrown?
Did you add the Public Enum outside the class definition?
Here how to retrieve data:
Private Sub GetData(ID As Integer)
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
Dim com As OleDbCommand = Nothing
Dim dr As OleDbDataReader = Nothing
Try
con.Open()
com = New OleDbCommand("SELECT * FROM table WHERE id = " & ID, con)
dr = com.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
dr.Read()
'assign data to labels and textboxes
someTextBox.Text = dr.Item("field1")
End If
dr.Close()
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Here's how to update the database:
Private Sub UpdateData(ID As Integer)
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
Dim com As OleDbCommand = Nothing
Try
con.Open()
com = New OleDbCommand("UPDATE table SET field1 = '" & someTextBox.Text & "' WHERE id = " & ID, con)
com.ExecuteNonQuery()
con.Close()
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
And finally, here's how to delete from the database:
Private Sub DeleteData(ID As Integer)
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
Dim com As OleDbCommand = Nothing
Try
con.Open()
com = New OleDbCommand("DELETE FROM table WHERE id = " & ID, con)
com.ExecuteNonQuery()
con.Close()
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
That's all there is to it.
And he answered your question.
By using the OpenFileDialog, you can browse the network to the other computer, select the file and open it. Network or Local, it makes no difference.
Or, if you know the path and the file you want to read is the same, over and over again. You can hard-code the path to the file via an UNC path: \\comp2\folder\filename.ext
Well.
You have the MouseEnter, MouseLeave and Click events.
And you also have the Width and Height properties.
*accidental double post*
Yes, there is.
This is a quick sample of how to accomplish that.
This is the button click.
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim login As LoginReturnCodes
Dim lif As New LoginForm()
If lif.ShowDialog() = DialogResult.OK Then
login = lif.Success
End If
lif.Dispose()
If login = LoginReturnCodes.Success Then
'Do some coding for successful login
ElseIf login = LoginReturnCodes.Failure Then
MessageBox.Show("Login failed. Please try again.")
Else
'Do nothing
End If
End Sub
Assuming that you already have a form in place for username and password, with a Login button and a Cancel button.
For the form, set the property AcceptButton to the Login button, and the property CancelButton to your Cancel button.
This is code for the login form.
Public Enum LoginReturnCodes
Success = 0
Failure = 1
End Enum
Public Class LoginForm
Private _success As LoginReturnCodes
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'Do some checking if username and password are valid
'If valid, set _success to LoginReturnCodes.Success
'If not valid, set _success to LoginReturnCodes.Failure
Me.Close()
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Public ReadOnly Property Success() As LoginReturnCodes
Get
Return _success
End Get
End Property
End Class
Looks good. Very interesting indeed.
A couple of questions though.
How compatible is it with all the HTML, CSS and javascript standards out there?
And for those of us who like to use keyboard shortcuts, for browsing pages, instead of using the mouse, how are you implementing those?
I'm assuming that you have a DataGridView on your form, named DataGridView1.
Dim cn As New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Wise-fps01\shared\vbDataBase.mdb")
cn.Open()
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM marketingDB WHERE company_name = 'Opfer Logan'", cn)
Dim table As New DataTable()
adapter.Fill(table)
cn.Close()
DataGridView1.DataSource = table
DataGridView.Update()
con.State gives you the state of the connection.
You can't SET the state that way, you can only read the state.
If con.State = ConnectionState.Open Then
con.Close()
End If
I'm using VS 2008.
And there is absolutely no reason to replace MessageBox with MsgBox.
MsgBox is the VB6 way, MessageBox is the VB.NET way.
Oh, and stop yelling.
We are civilized people here, aren't we?
Your welcome. :)
Please do mark the thread as solved.
Then I do apologize. I have no idea of how to implement that.
I believe the answer to your original question, a dynamically visible column, lies in the property Visible for the Columns collection.
If DataGridView1.Rows(243).Cells(2).Value.Equals("some value") Then
DataGridView1.Columns(5).Visible = False
End If
Assuming that column1 contains a path to the picture.
Here's what you can do.
First change the property AllowDragDrop to True for all the pictureboxes.
Then add this code:
Dim bMouseIsDown As Boolean = False
Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
bMouseIsDown = True
End If
End Sub
Private Sub DataGridView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
If DataGridView1.SelectedRows.Count > 0 Then
If bMouseIsDown Then
Dim path As String = DataGridView1.SelectedRows(0).Cells(1).Value
DataGridView1.DoDragDrop(path, DragDropEffects.Copy)
End If
End If
End Sub
'Repeat these two for all the pictureboxes
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.StringFormat) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
Dim path As String = DirectCast(e.Data.GetData(DataFormats.StringFormat), String)
Dim stream As New IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Dim img As Image = Image.FromStream(stream)
PictureBox1.Image = img
End Sub
You are probably getting an error because you are missing the field names in the INSERT query.
Try this:
Dim con As New SqlClient.SqlConnection("Server=iraq\SQLEXPRESS; Database=stats; Trusted_Connection=True;")
Dim com As New SqlClient.SqlCommand("insert into users (field1,field2,field3) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')", con)
Try
con.Open()
com.ExecuteNonQuery()
con.Close ()
Catch ex As Exception
' This will give you the exact error of what's going wrong
MessageBox.Show(ex.ToString())
End Try
You can try this.
Put a button of your form and call it btnImport.
Then add this code.
Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
Dim fileName As String = ""
Dim ofd As New OpenFileDialog
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
fileName = ofd.FileName
PerformImportToSql(fileName)
End If
End Sub
Private Sub PerformImportToSql(ByVal Filename As String)
Dim table As DataTable = New DataTable
Dim accConnection As New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; DataSource=" & Filename & ";User Id=admin; Password=;")
Dim sqlConnection As New SqlClient.SqlConnection("Data Source=yourServer; Initial Catalog=yourDatabase; User Id=yourUsername; Password=yourPassword;")
Try
'Import the Access data
accConnection.Open()
Dim accDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM <tablename>", accConnection)
accDataAdapter.Fill(table)
accConnection.Close()
'Export to MS SQL
sqlConnection.Open()
Dim sqlDataAdapter As New SqlClient.SqlDataAdapter("SELECT * FROM <tablename>", sqlConnection)
Dim sqlCommandBuilder As New SqlClient.SqlCommandBuilder(sqlDataAdapter)
sqlDataAdapter.InsertCommand = sqlCommandBuilder.GetInsertCommand()
sqlDataAdapter.UpdateCommand = sqlCommandBuilder.GetUpdateCommand()
sqlDataAdapter.DeleteCommand = sqlCommandBuilder.GetDeleteCommand()
sqlDataAdapter.Update(table)
sqlConnection.Close()
Catch ex As Exception
If accConnection.State = ConnectionState.Open Then
accConnection.Close()
End If
If sqlConnection.State = ConnectionState.Open Then
sqlConnection.Close()
End If
MessageBox.Show("Import failed with error: " & Environment.NewLine & Environment.NewLine _
& ex.ToString)
End Try
End Sub
You can do this.
Add the breakpoint, then right-click on the mark and select Location.
In the dialog-box that pops up, check the box "Allow the source code to be different from the original version". Hit OK.
That should work.
Well. What can I say.
It's not an easy thing to accomplish.
The quickest course of action I can think of is using some API from PartitionMagic or something similar.
No problem. :)
If you find my help useful, then please mark this thread as solved.
So? The only real difference between C# and VB.NET, is the syntax.
So, it's quite easy to translate between the two languages.
Especially if you use this as a tool.
You can post entire classes of code, and the converter translates them for you.
Yeah. Only one, though you may have tried it already.
You can treat the excel file as a database, and use OleDb and OleDbDataAdapter to push the data into it.
Private Sub MethodThatCreatesDynamicPictureBoxes()
'Your code for dynamically creating picturebox
AddHandler yourPicBox.Click, AddressOf picbox_Click
End Sub
Private Sub picbox_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Every time a picturebox is clicked, this variable will contain THAT picturebox
Dim picBox As PictureBox = DirectCast(sender, PictureBox)
'Do something with the picBox control
End Sub
It's seems so.
Have you tried google, keywords VB.NET AND partitioning? Perhaps you'll find something there to help you.
Well, belle.
What would you like to know more precisely?
There are a lot of things you can do with the ListView control.
The ListView control is simply to, well, list things from top to bottom.
If you put a ListView control on a form, you can do this in the Form_Load event:
ListView1.Items.Add("item1")
ListView1.Items.Add("item2")
ListView1.Items.Add("item3")
You should have a look into the third-party component GemBox.SpreadSheet.
I'm using it myself, and it's very very fast.
Dude. Wrong forum.
But those errors seem pretty obvios to me.
Examine the code at lines 116, 117 and 118.
Well. I figured that since you mentioned that the target would be a trashcan, then there would be no point in assigning an image to the target picturebox. That's why changed that line.
Ok. Then we need to change some things for the source picturebox.
Private bMouseIsDown As Boolean = False
Private Sub sourcePictureBox_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles sourcePictureBox.MouseDown
If sourcePictureBox.Image IsNot Nothing Then
bMouseIsDown = True
End If
End Sub
Private Sub sourcePictureBox_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles sourcePictureBox.MouseMove
If bMouseIsDown Then
Dim pic As PictureBox = DirectCast(sender, PictureBox)
Dim img As BitMap = pic.Image
pic.Image = Nothing
pic.DoDragDrop(img, DragDropEffects.Move)
' Or if you prefer to just copy the picture
'pic.DoDragDrop(img, DragDropEffects.Copy)
End If
bMouseIsDown = False
End Sub
And for the target.
Private Sub targetPictureBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles targetPictureBox.DragDrop
If e.Data.GetDataPresent(DataFormat.BitMap) Then
Dim img As BitMap = e.Data.GetData(DataFormats.BitMap)
If img <> sourcePictureBox.Image Then 'I don't know if this one will work
sourcePictureBox.Image = img 'Restore the picture from the source
End If
End If
End Sub
And for the visibility while dragging. I found a discussion on another site that will give you the answer to that one. It will give a complete method for drag and drop of image.
http://www.tek-tips.com/viewthread.cfm?qid=1241165&page=1
This is an example of how to use the BETWEEN condition in an SQL query.
SELECT *
FROM orders
WHERE order_date BETWEEN to_date ('2010/01/01', 'yyyy/mm/dd')
AND to_date ('2010/01/30', 'yyyy/mm/dd'
You're very welcome. :)
Please remember to mark this thread as solved.
First.
In the form load event, add this line: targetPictureBox.AllowDrop = True
For the source picturebox, add this method:
Private Sub sourcePictureBox_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles sourcePictureBox.MouseDown
Dim pic As PictureBox = DirectCast(sender, PictureBox)
pic.DoDragDrop(pic.Image, DragDropEffects.Move)
' Or if you prefer to just copy the picture
'pic.DoDragDrop(pic.Image, DragDropEffects.Copy)
End Sub
For the target picturebox, add these two methods:
Private Sub targetPictureBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles targetPictureBox.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap)
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub targetPictureBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles targetPictureBox.DragDrop
If e.Data.GetDataPresent(DataFormat.BitMap) Then
Dim img As BitMap = e.Data.GetData(DataFormats.BitMap)
'Insert comparison code here
targetPictureBox.Image = img
End If
End Sub
If you don't use the username than you need something else to limit the results from the database query, like name and/or surname.
SELECT * FROM table WHERE name = 'john' AND surname = 'smith'
Good luck!
Ok.
I figured it out.
Replace all instances of SendKey "{DOWN}" with this line: ActiveCell.Offset(1, 0).Select
Yeah. I can see that.
Do this instead.
Label43.Text = DateTime.Now.ToString("HH:mm:ss")
Dim time1 As DateTime = DateTime.Parse("1970-01-01 23:50:00")
Dim time2 As DateTime = DateTime.Parse("1970-01-01 23:51:00")
Dim compare As DateTime = DateTime.Parse("1970-01-01 " & Label43.Text)
If compare > time1 AndAlso compare < time1 Then