Jump to content
Xtreme .Net Talk

TedN

Avatar/Signature
  • Posts

    35
  • Joined

  • Last visited

TedN's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. OK. I found the problem. I downloaded and installed Unlocker and it showed the only process that was using the dat file was Visual Studio. So it was obviously my code. By a process of elimination Unlocker was able to show when the dat file became used. And there it was, right at the beginning of the program where I opened a streamreader to check the password. I'd forgotten all about that - most embarrassing. I hadn't closed out the streamreader completely. Strange the program worked OK in VS 2003.
  2. My program firsts reads a file then writes to the file. The program used to work fine on my old XP Home OS and using Visual Studio 2003. I've since changed to XP Pro and installed Visual Studio 2005. I now get the following error: "The process cannot access the file "C:\Haven.dat" because it is being used by another process." It's got something to do with Haven.dat still being in use. The relevant code is as follows: Public Function Decrypt() As Integer Dim fsRead As FileStream Dim encStream As CryptoStream Dim sr As StreamReader fsRead = New FileStream("C:\Haven.dat", FileMode.Open, FileAccess.Read) encStream = New CryptoStream(fsRead, key.CreateDecryptor(), CryptoStreamMode.Read) sr = New StreamReader(encStream) fsRead.Close() encStream.Close() sr.Close() fsRead.Dispose() encStream.Dispose() sr.Dispose() End Function Public Function Encrypt() As Integer Dim fsWrite As New FileStream Dim encStream As CryptoStream Dim sw As StreamWriter [b]fsWrite = New FileStream("C:\Haven.dat", FileMode.Create, FileAccess.Write)[/b] encStream = New CryptoStream(fsWrite, key.CreateEncryptor(), CryptoStreamMode.Write) sw = New System.IO.StreamWriter(encStream) fsWrite.Close() encStream.Close() sw.Close() fsWrite.Dispose() encStream.Dispose() sw.Dispose() End Function The error occurs at the bolded line. As a test I made a copy of the dat file and referenced the copy in the bolded line. There was then no error so it means that the original dat file is not being closed down. Your help would be much appreciated.
  3. Found the answer. I needed to use sender instead of ctl in the following lines of code. If TypeOf sender Is Label Then MsgBox(sender.Name) End If
  4. I have a form with a multitude of labels. I would like to code a generic event handler so that a click on any of the labels would fire a single event. The following code was adapted from a search on this site. I have set it up so that when a label is clicked the label name should be displayed in a message box. For this test case I only have two labels (Label1, Label2) on a form. The problem is that the message displayed is always "Label1" regardless as to whether I click on the form, Label1 or Label2. Public Class Form1 Inherits System.Windows.Forms.Form Dim ctl As Control Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load AddGenericClickHandler(Me, AddressOf Generic_Click) End Sub Sub Generic_Click(ByVal sender As Object, ByVal e As EventArgs) If TypeOf ctl Is Label Then MsgBox(ctl.Name) End If End Sub Private Sub AddGenericClickHandler(ByVal Parent As Control, _ ByVal Handler As EventHandler) For Each ctl In Parent.Controls AddHandler ctl.Click, Handler Next AddHandler Parent.Click, Handler End Sub End Class Your help would be much appreciated. Thanks, Ted
  5. Duh! I was removing column before making datagridview visible. Make it visible first and column can be removed.
  6. Is there a way to remove a column from a DataGridView. I fill the datagridview from a dataset. The dataset has a column of data that I no longer require. I've tried getting rid of the column in the dataset without success. ds.Tables("Asset").Columns(6).Dispose() doesn't appear to do anything. So I then tried to remove the column from the datagridview. I've tried: dgPrio.Columns.Remove("CLASS") dgPrio.Columns.RemoveAt("CLASS") and various other combinations. All that happens is the column I wish to remove moves to the end. Appreciate any help. Thanks, Ted
  7. Re: DataGridView.CellPainting Thanks for your code, it works fine. Very much appreciated. Just gotta find the way of increasing the header height. Thanks again, Ted
  8. Re: DataGridView.CellPainting Thank you for this. It's beginning to sink in that with Graphics one needs a sub routine that repaints on an as required basis, as you mentioned in one of your previous posts. I won't be able to get back to this until next week. But I look forward to trying this out and hopefully with some success. Thank you again for all your help. TedN
  9. I really appreciate all the advice. However, I think I'm reaching the end of the line here. What I really wanted to do was to put vertical text in the column headers of a DataGridView. I have fairly lengthy column headers which can't really be shortened. This means that the columns are unnecessarily wide. This work was originally displayed on an Excel spreadsheet where there's no problem aligning the column header text vertically. If I'm having this much of a problem with a simple label then I think that DataGridView column headers are well beyond my reach. If anyone out there knows of an alternative to a DataGridView where column header text can be displayed vertically I'd appreciate knowing. Thanks for your time. Ted
  10. Thanks for all of your replies. I've modified the code so that when the form loads it calls a sub routine which should cause vertical text to appear on a label. The program runs but the label remains blank. Appreciate it if someone could point me to what I'm doing wrong. Public Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load VertText(Label1) End Sub Private Sub VertText(ByVal control As Control) Dim sName As String = "TedN" Dim g As Graphics = control.CreateGraphics Dim oBrush As New SolidBrush(Color.Black) Dim oFont As New Font("Tahoma", 32, FontStyle.Bold) Dim oStrFormat As New StringFormat(StringFormatFlags.DirectionVertical) g.DrawString(sName, oFont, oBrush, 0.0F, 0.0F, oStrFormat) End Sub Thanks, TedN
  11. The following code causes a string to be written vertically on a form. The code runs automatically when the form is opened. Public Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As PaintEventArgs) Handles MyBase.Paint Dim sName As String = "TedN" With [b]e[/b].Graphics Dim oBrush As New SolidBrush(Color.Black) Dim oFont As New Font("Tahoma", 32, FontStyle.Bold) Dim oStrFormat As New StringFormat(StringFormatFlags.DirectionVertical) .DrawString(sName, oFont, oBrush, 0.0F, 0.0F, oStrFormat) End With End Sub I would like to put the code in a simple little sub routine that would be called when the form loads or a button clicked, etc. I've tried every whichway to get rid of the "e" component which I assume is tied to an event. I don't want the code to run directly from an event. How the heck do I do that. Thanks, Ted
  12. I currently download data from a database into a Dataset table, then display the data in a DataGridView. I would like to sort on more than one column at a time in the DataGridView. Can this be done? Also, my column headings need to be quite descriptive which leads to unnecessarily wide columns. Is there a way of turning the text on its side (as in an Excel spreadsheet) to allow narrower columns. Thanks, Ted
  13. OK. Found the answer. Use two DataAdapters.
  14. I've created two query strings to get data from various tables in a database. I would like to fill two table tables in a dataset with the data from each query string, e.g. sqlStr1 data into dsTable1 sqlStr2 data into dsTable2. I've tried the following and many other combinations but none seem to work. con.Open cmd.CommandText = sqlStr1 da.Fill(ds, "dsTable1") cmd.CommandText = sqlStr2 da.Fill(ds, "dsTable2") con.Close I don't need any interoperability between the two tables. I'm placing the data in separate tables simply for the sake of clarity. I would also prefer not to combine the two query strings. Thanks, Ted
  15. OK. I finally got it to work. Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim da As OleDb.OleDbDataAdapter Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim ds As New DataSet Dim dv As New DataView Dim sql As String da = New OleDb.OleDbDataAdapter(cmd) con = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source = C:\AddressBook.mdb") sql = "SELECT * FROM tblContacts WHERE Surname = @sName" cmd.Parameters.Add("@sName", OleDb.OleDbType.Char).Value = "Smith" cmd.Connection = con cmd.CommandText = sql con.Open() da.Fill(ds, "Test") con.Close() dv.Table = ds.Tables("Test") Me.DataGrid1.DataSource = dv End Sub Can't say I've got a complete handle on it yet but it's a start.
×
×
  • Create New...