Friday, August 31, 2007

Database Connection Strings

Getting the right connection string syntax can chew up hours of experimentation. Here is a site that can save that time for you: http://www.carlprothman.net/Default.aspx?tabid=81

Sunday, August 19, 2007

Finding the Size of a file while Writing when using StreamWriter

In VB 6, you could always use LOF() to find the length of the file you were writing; however, in VB.NET or C# is not as obvious.


Dim s As StreamWriter = New StreamWriter(filename)
.
.
.
s.BaseStream.Flush()
Dim offsetPosition as Long = s.BaseStream.Length



One thing to note, you will have to do the Flush before using the length property or you will not get accurate results. You can also set the AutoFlush property on the StreamWriter object.


For more info, see:

http://www.thescripts.com/forum/thread266352.html

Monday, August 13, 2007

Using a ListView in VB.NET

Here is a basic example of how to use the Detail View with a ListView in VB.NET.
See also AutoFitListView and CopyListViewToClipboard.

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

' Set ListView Properties
ListView1.View = View.Details
ListView1.GridLines = True
ListView1.FullRowSelect = True
ListView1.HideSelection = False
ListView1.MultiSelect = False

' Create Columns Headers
ListView1.Columns.Add("Column A")
ListView1.Columns.Add("Column B")
ListView1.Columns.Add("Column C")

Dim tempValue As Integer = 0

For i As Integer = 0 To 9

' Create List View Item (Row)
Dim lvi As New ListViewItem

' First Column can be the listview item's Text
lvi.Text = "Row " + i.ToString

' Second Column is the first sub item
tempValue = tempValue + 1
lvi.SubItems.Add(tempValue.ToString)

' Third Column is the second sub item
tempValue = tempValue + 1
lvi.SubItems.Add(tempValue.ToString)

' Add the ListViewItem to the ListView
ListView1.Items.Add(lvi)

Next

End Sub

Private Sub ListView1_SelectedIndexChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles ListView1.SelectedIndexChanged

If ListView1.SelectedIndices.Count = 0 Then Return

Dim lvi As ListViewItem = _
ListView1.SelectedItems(0)

MessageBox.Show(lvi.Text + " has been selected.")

End Sub

Monday, August 6, 2007

Critical Section in C#

Here is a good article on using the lock statement to create critical sections in C#:

http://www.calcaria.net/c-sharp/2006/10/c-equivalent-csinglelock-critical.html

Here is the gist:

Object lockobj = new Object();

lock (lockobj)
{
// Do your locked work
}