|
How to get Excel version
(Tuesday, February 01, 2005)
Found the following interesting discussion in the Newsgroups:
How to get Excel version by:Anonymous
| Hi,
I'd like to know how to get Excel version (2000, 2002, 2003, etc).
Thanks in advance
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | * "=?Utf-8?B?TGkgUGFuZw==?=" <LiPang@discussions.microsoft.com> scripsit: > I'd like to know how to get Excel version (2000, 2002, 2003, etc).
What if there is more than one excel version installed?
:-)
-- Herfried K. Wagner [MVP]
| | | Reply: by:Anonymous
| | | Get the highest version.
| | | Reply: by:Anonymous
| | | I wrote a sample code which worked Private Sub DetectExcelVersion()
Dim i As Integer For i = 20 To 1 Step -1 Try If IsReference(CreateObject("Excel.Application" & "." & i)) Then MsgBox("Excel version is " & i) End If Catch ex As Exception MsgBox(ex.Message.ToString & " Excel.Application" & "." & i) End Try Next
End Sub
|
Posted by Xander Zelders

How to start/stop IIS service
Found the following interesting discussion in the Newsgroups:
How to start/stop IIS service by:Anonymous
| I used the following code to manage IIS service
Dim iis As New System.ServiceProcess.ServiceController("IIS Admin Service") If iis.Status() = ServiceProcess.ServiceControllerStatus.Stopped Then iis.Start() End If
but IIS couldn't start. Did I do the correct thing?
| | | Reply: by:Anonymous
| | | The name of IIS service is "World Wide Web Publishing Service".
| | | Reply: by:One Handed Man \( OHM - Terry Burns \)
| | | System.Diagnostics.Process.Start("C:\WINDOWS\System32\inetsrv\inetinfo.exe") --
OHM ( Terry Burns ) . . . One-Handed-Man . . .
|
Posted by Xander Zelders

performance??
Found the following interesting discussion in the Newsgroups:
performance?? by:pproost@hotmail.com (Piedro)
| Hi group I'm writing an application for calculating prices and stuff. On my pc(P4 2,4GHz 512MB Ram ) it works just fine but if I test it on a pentium 1 or 2 with 64 MB RAM it obviously is slower. But it seems that the app goes slow if I use a lot of property's, for example I've got a form with a tabcontrol and 3 tabpages, on each tabpage is a usercontrol. On the first screen the user needs to select all kinds of stuff and this needs to be transfered to the 2nd tabpage, so in my user controls I've made for example 9 propertys and when I change the tabpage I pass on my propertys to the next usercontrol (for example if I change from tabpage1 to the tabpage2: usercontrol2.user = usercontrol1.user and the same for the other 8 property's) and this takes a lot of time (5 seconds before the next tabpage shows). I've also got another form with a tabcontrol and 4 tabpages, and they work just fine because here I only pass 1 property (the switch between the tabpages only takes a split second). Can someone advice me how to make it faster.
thnx in advance Peter
| | | Reply: by:Cor Ligthert
| | | Hi Peter,
I think there is no beter link than this one.
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp
I hope this helps?
Cor
| | | Reply: by:pproost@hotmail.com (Piedro)
| | | Thnx Cor
I've only had quick glance but it will probably help me a lot.
Thnx again Peter
|
Posted by Xander Zelders

performance??
Found the following interesting discussion in the Newsgroups:
performance?? by:pproost@hotmail.com (Piedro)
| Hi group I'm writing an application for calculating prices and stuff. On my pc(P4 2,4GHz 512MB Ram ) it works just fine but if I test it on a pentium 1 or 2 with 64 MB RAM it obviously is slower. But it seems that the app goes slow if I use a lot of property's, for example I've got a form with a tabcontrol and 3 tabpages, on each tabpage is a usercontrol. On the first screen the user needs to select all kinds of stuff and this needs to be transfered to the 2nd tabpage, so in my user controls I've made for example 9 propertys and when I change the tabpage I pass on my propertys to the next usercontrol (for example if I change from tabpage1 to the tabpage2: usercontrol2.user = usercontrol1.user and the same for the other 8 property's) and this takes a lot of time (5 seconds before the next tabpage shows). I've also got another form with a tabcontrol and 4 tabpages, and they work just fine because here I only pass 1 property (the switch between the tabpages only takes a split second). Can someone advice me how to make it faster.
thnx in advance Peter
| | | Reply: by:Cor Ligthert
| | | Hi Peter,
I think there is no beter link than this one.
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp
I hope this helps?
Cor
| | | Reply: by:pproost@hotmail.com (Piedro)
| | | Thnx Cor
I've only had quick glance but it will probably help me a lot.
Thnx again Peter
|
Posted by Xander Zelders

Where are the Form Templates in .NEt that was included in VB6?
Found the following interesting discussion in the Newsgroups:
Where are the Form Templates in .NEt that was included in VB6? by:Lars Netzel
| In VB6 I remember finding templates for forms like "About " and "Licence Agreemenet" and so on when creating a new Form.
Where are they in .NET, not included? Can you download Froms like that, for example an About form.. to get the Design right?
/Lars Netzel
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | There are no such templates included. But there are good news: In VB 2005, the templates will come back.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
| | | Reply: by:Lars Netzel
| | | ah, okay.. So I will have to pay tons of money again to get this... too bad
/Lars
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | Let's hope that there is a $ 31 upgrade again ;-)
-- Herfried K. Wagner [MVP]
|
Posted by Xander Zelders

Working Code of Bound dropdownlist in Datagrid
Found the following interesting discussion in the Newsgroups:
Working Code of Bound dropdownlist in Datagrid by:jimb
| I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it.
Anybody have a working example of a dropdownlist in an editable grid?
Thanks.
-- .. http://sf-f.org, weblog and search engine for fans and writers of speculative fiction. ..
| | | Reply: by:scorpion53061
| | | http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q480q
http://www.syncfusion.com/faq/winforms/Files/DataGridBoundCombo_vb.zip
http://dotnet.leadit.be/extendeddatagrid
http://www.knowdotnet.com/articles/kdngrid.html
code by "Cor":
Option Strict On Option Explicit On Public Class DataGridCombo Inherits ComboBox Public Sub New() MyBase.New() End Sub End Class Public Class DataGridComboColumnStyle Inherits DataGridColumnStyle Private xMargin As Integer = 2 Private yMargin As Integer = 1 Private WithEvents Combo As DataGridCombo Private mDisplayMember As String Private mValueMember As String Private mSource As CurrencyManager Private mRowNum As Integer Private OldVal As String = String.Empty Private InEdit As Boolean = False Public Sub New(ByRef DataSource As DataTable, ByVal DisplayMember As Integer, ByVal ValueMember As Integer) Combo = New DataGridCombo mDisplayMember = DataSource.Columns.Item(DisplayMember).ToString mValueMember = DataSource.Columns.Item(ValueMember).ToString Combo.Visible = True Combo.DataSource = DataSource Combo.DisplayMember = mDisplayMember Combo.ValueMember = mValueMember Combo.DropDownStyle = ComboBoxStyle.DropDownList Combo.Bounds = Rectangle.Empty End Sub Public Sub New(ByRef DataSource As DataTable, ByVal DisplayMember As String, ByVal ValueMember As String) Combo = New DataGridCombo mDisplayMember = DisplayMember mValueMember = ValueMember Combo.Visible = True Combo.DataSource = DataSource Combo.DisplayMember = mDisplayMember Combo.ValueMember = mValueMember Combo.DropDownStyle = ComboBoxStyle.DropDownList Combo.Bounds = Rectangle.Empty End Sub Protected Overloads Overrides Sub Abort(ByVal RowNum As Integer) Debug.WriteLine("Abort()") RollBack() HideComboBox() EndEdit() End Sub Protected Overloads Overrides Function Commit(ByVal DataSource As CurrencyManager, ByVal RowNum As Integer) As Boolean HideComboBox() If InEdit Then Try Dim Value As Object = Combo.SelectedValue If NullText.Equals(Value) Then Value = DBNull.Value End If SetColumnValueAtRow(DataSource, RowNum, Value) Catch RollBack() Return False End Try EndEdit() End If Return True End Function Protected Overloads Overrides Sub ConcedeFocus() Combo.Visible = False InEdit = False End Sub Protected Overloads Overrides Sub Edit(ByVal Source As CurrencyManager, _ ByVal Rownum As Integer, _ ByVal Bounds As Rectangle, _ ByVal [ReadOnly] As Boolean, _ ByVal InstantText As String, _ ByVal CellIsVisible As Boolean) mSource = Source mRowNum = Rownum Combo.Text = "" Dim OriginalBounds As Rectangle = Bounds OldVal = Combo.Text If CellIsVisible Then Bounds.Offset(xMargin, yMargin) Bounds.Width -= xMargin * 2 Bounds.Height -= yMargin Combo.Bounds = Bounds Combo.Visible = True Else Combo.Bounds = OriginalBounds Combo.Visible = False End If Dim TextObject As Object = GetColumnValueAtRow(Source, Rownum) If Not TextObject Is System.DBNull.Value Then Combo.SelectedValue = TextObject.ToString() If Not InstantText Is Nothing Then Combo.SelectedValue = InstantText End If Combo.RightToLeft = Me.DataGridTableStyle.DataGrid.RightToLeft If InstantText Is Nothing Then Combo.SelectAll() Else Combo.Select(Combo.Text.Length, 0) End If If Combo.Visible Then DataGridTableStyle.DataGrid.Invalidate(OriginalBounds) End If InEdit = True End Sub Protected Overloads Overrides Function GetMinimumHeight() As Integer Return Combo.PreferredHeight + yMargin End Function Protected Overloads Overrides Function GetPreferredHeight(ByVal g As Graphics, ByVal Value As Object) As Integer Debug.WriteLine("GetPreferredHeight()") Dim NewLineIndex As Integer = 0 Dim NewLines As Integer = 0 Do Until NewLineIndex = -1 NewLineIndex = DirectCast(Value, String).IndexOf("r\n", NewLineIndex + 1) NewLines += 1 Loop Return FontHeight * NewLines + yMargin End Function Protected Overloads Overrides Function GetPreferredSize(ByVal g As Graphics, ByVal Value As Object) As Size Dim Extents As Size = Size.Ceiling(g.MeasureString(GetText(Value), _ Me.DataGridTableStyle.DataGrid.Font)) Extents.Width += xMargin * 2 + DataGridTableGridLineWidth Extents.Height += yMargin Return Extents End Function
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Source As CurrencyManager, _ ByVal RowNum As Integer) Paint(g, Bounds, Source, RowNum, False) End Sub Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Source As CurrencyManager, _ ByVal RowNum As Integer, _ ByVal AlignToRight As Boolean) Dim objText As Object = GetColumnValueAtRow(Source, RowNum) Dim Text As String = LookupDisplayValue(objText) PaintText(g, Bounds, Text, AlignToRight) End Sub Protected Overloads Sub Paint(ByVal g As Graphics, ByVal Bounds As Rectangle, ByVal Source As CurrencyManager, _ ByVal RowNum As Integer, ByVal BackBrush As Brush, ByVal ForeBrush As Brush, ByVal AlignToRight As Boolean) Dim objText As Object = GetColumnValueAtRow(Source, RowNum) Dim Text As String = LookupDisplayValue(objText) PaintText(g, Bounds, Text, AlignToRight) End Sub Protected Overloads Overrides Sub SetDataGridInColumn(ByVal Dg As DataGrid) MyBase.SetDataGridInColumn(Dg) If Not Combo.Parent Is Dg Then If Not Combo.Parent Is Nothing Then Combo.Parent.Controls.Remove(Combo) End If End If If Not Dg Is Nothing Then Dg.Controls.Add(Combo) End Sub Protected Overloads Overrides Sub UpdateUI(ByVal Source As CurrencyManager, ByVal RowNum As Integer, ByVal InstantText As String) Combo.Text = GetText(GetColumnValueAtRow(Source, RowNum)) If Not (InstantText Is Nothing) Then Combo.Text = InstantText End If End Sub Private ReadOnly Property DataGridTableGridLineWidth() As Integer Get If Me.DataGridTableStyle.GridLineStyle = DataGridLineStyle.Solid Then Return 1 Else Return 0 End If End Get End Property Private Sub EndEdit() InEdit = False Invalidate() End Sub Private Function GetText(ByVal Value As Object) As String If Value Is System.DBNull.Value Then Return NullText If Not Value Is Nothing Then Return Value.ToString Else Return String.Empty End If End Function Private Sub HideComboBox() If Combo.Focused Then Me.DataGridTableStyle.DataGrid.Focus() End If Combo.Visible = False End Sub Private Sub RollBack() Combo.Text = OldVal End Sub Private Sub PaintText(ByVal g As Graphics, ByVal Bounds As Rectangle, ByVal Text As String, ByVal AlignToRight As Boolean) Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor) Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor) PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight) End Sub Private Sub PaintText(ByVal g As Graphics, ByVal TextBounds As Rectangle, ByVal Text As String, ByVal BackBrush As Brush, ByVal ForeBrush As Brush, ByVal AlignToRight As Boolean) Dim Rect As Rectangle = TextBounds Dim RectF As RectangleF = RectF.op_Implicit(Rect) ' Convert to RectangleF Dim Format As StringFormat = New StringFormat If AlignToRight Then Format.FormatFlags = StringFormatFlags.DirectionRightToLeft End If Select Case Me.Alignment Case Is = HorizontalAlignment.Left Format.Alignment = StringAlignment.Near Case Is = HorizontalAlignment.Right Format.Alignment = StringAlignment.Far Case Is = HorizontalAlignment.Center Format.Alignment = StringAlignment.Center End Select Format.FormatFlags = Format.FormatFlags Or StringFormatFlags.NoWrap g.FillRectangle(Brush:=BackBrush, Rect:=Rect) Rect.Offset(0, yMargin) Rect.Height -= yMargin g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format) Format.Dispose() End Sub
Private Sub ComboChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo.SelectionChangeCommitted SetColumnValueAtRow(_source, _rowNum, Combo.SelectedValue) ColumnStartedEditing(Combo) End Sub
Private Function LookupDisplayValue(ByVal LookupObject As Object) As String If LookupObject Is System.DBNull.Value Then Return NullText Dim LookupText As String = LookupObject.ToString Dim I As Integer Dim IMax As Integer = Combo.Items.Count - 1 Dim DT As DataTable = CType(Combo.DataSource, DataTable) For I = 0 To IMax If DT.Rows(I)(mValueMember).ToString = LookupText Then Return DT.Rows(I)(mDisplayMember).ToString End If Next Return String.Empty End Function End Class Code by "pmcguire":
Option Strict Off Option Explicit On Imports System.Collections Imports System.ComponentModel Imports System.Drawing Imports System.Windows.Forms Imports System.Data
Namespace DataGridComboBoxColumnStyle Public Class DataGridComboBox Inherits ComboBox Public Sub New() MyBase.New() End Sub
Private _modified As Boolean = False
Public isInEditOrNavigateMode As Boolean = True
Public Property Modified() As Boolean Get Return _modified End Get Set(ByVal Value As Boolean) _modified = Value End Set End Property
End Class Public Class DataGridComboBoxColumn Inherits DataGridColumnStyle ' ' UI constants ' Private xMargin As Integer = 2 Private yMargin As Integer = 1 Private WithEvents Combo As DataGridComboBox Private WithEvents tb As TextBox Private _DisplayMember As String Private _ValueMember As String Private _rowNum As Integer Private WithEvents _source As CurrencyManager ' ' Used to track editing state ' Private OldVal As String = String.Empty Private InEdit As Boolean = False ' ' Create a new column - DisplayMember, ValueMember ' Passed by ordinal ' Public Sub New() Combo = New DataGridComboBox Combo.Visible = False tb = New TextBox tb.Visible = False End Sub
Public Sub New(ByRef DataSource As DataTable, _ ByVal DisplayMember As Integer, _ ByVal ValueMember As Integer)
Debug.WriteLine("New(1)") Combo = New DataGridComboBox _DisplayMember = DataSource.Columns.Item(index:=DisplayMember).ToString _ValueMember = DataSource.Columns.Item(index:=ValueMember).ToString
With Combo ..Visible = False ..DataSource = DataSource ..DisplayMember = _DisplayMember ..ValueMember = _ValueMember End With tb = New TextBox With tb ..Visible = False End With End Sub ' ' Create a new column - DisplayMember, ValueMember ' passed by string ' Public Sub New(ByRef DataSource As DataTable, _ ByVal DisplayMember As String, _ ByVal ValueMember As String)
Debug.WriteLine("New(2)") Combo = New DataGridComboBox With Combo ..Visible = False ..DataSource = DataSource ..DisplayMember = DisplayMember ..ValueMember = ValueMember End With tb = New TextBox With tb ..Visible = False End With End Sub Public Sub New(ByRef DataSource As DataView, _ ByVal DisplayMember As Integer, _ ByVal ValueMember As Integer)
Debug.WriteLine("New(3)") Combo = New DataGridComboBox _DisplayMember = DataSource.Table.Columns.Item(index:=DisplayMember).ToString _ValueMember = DataSource.Table.Columns.Item(index:=ValueMember).ToString
With Combo ..Visible = False ..DataSource = DataSource ..DisplayMember = _DisplayMember ..ValueMember = _ValueMember End With tb = New TextBox With tb ..Visible = False End With End Sub ' ' Create a new column - DisplayMember, ValueMember ' passed by string ' Public Sub New(ByRef DataSource As DataView, _ ByVal DisplayMember As String, _ ByVal ValueMember As String)
Debug.WriteLine("New(4)") Combo = New DataGridComboBox With Combo ..Visible = False ..DataSource = DataSource ..DisplayMember = DisplayMember ..ValueMember = ValueMember End With tb = New TextBox With tb ..Visible = False End With End Sub
'------------------------------------------------------ ' Methods overridden from DataGridColumnStyle '------------------------------------------------------ ' ' Abort Changes ' Protected Overloads Overrides Sub Abort(ByVal RowNum As Integer) Debug.WriteLine("Abort()") RollBack() HideComboBox() EndEdit() End Sub ' ' Commit Changes ' Protected Overloads Overrides Function Commit(ByVal DataSource As CurrencyManager, _ ByVal RowNum As Integer) As Boolean Debug.WriteLine("Commit()") HideComboBox() _rowNum = RowNum _source = DataSource If Not InEdit Then Return True End If
Try Dim Value As Object = Combo.SelectedValue If NullText.Equals(Value) Then Value = Convert.DBNull End If tb.Text = Combo.Text SetColumnValueAtRow(DataSource, RowNum, Value) Catch e As Exception RollBack() Return False End Try EndEdit() Return True End Function ' ' Remove focus ' Protected Overloads Overrides Sub ConcedeFocus() Debug.WriteLine("ConcedeFocus()") Combo.Visible = False End Sub ' ' Edit Grid ' Protected Overloads Overrides Sub Edit(ByVal Source As CurrencyManager, _ ByVal Rownum As Integer, _ ByVal Bounds As Rectangle, _ ByVal [ReadOnly] As Boolean, _ ByVal InstantText As String, _ ByVal CellIsVisible As Boolean)
Debug.WriteLine("Edit()") Combo.Text = String.Empty
Dim OriginalBounds As Rectangle = Bounds Dim txt As String
OldVal = Combo.Text
If CellIsVisible Then Bounds.Offset(xMargin, yMargin) Bounds.Width -= xMargin * 2 Bounds.Height -= yMargin Combo.Bounds = Bounds Combo.Visible = True Else Combo.Bounds = OriginalBounds Combo.Visible = False End If
txt = tb.Text If Not txt = InstantText Then Combo.Modified = True End If If Not txt = NullText Then Combo.SelectedValue = GetText(GetColumnValueAtRow(Source, Rownum)) End If
If Not InstantText Is Nothing Then Combo.SelectedValue = InstantText End If
Combo.RightToLeft = Me.DataGridTableStyle.DataGrid.RightToLeft Combo.Focus()
If InstantText Is Nothing Then Combo.SelectAll() Else Dim [End] As Integer = Combo.Text.Length Combo.Select([End], 0) End If
If Combo.Visible Then DataGridTableStyle.DataGrid.Invalidate(OriginalBounds) End If
InEdit = True
End Sub
Protected Overloads Overrides Function GetMinimumHeight() As Integer ' ' Set the minimum height to the height of the combobox ' Debug.WriteLine("GetMinimumHeight()") Return Combo.PreferredHeight + yMargin End Function
Protected Overloads Overrides Function GetPreferredHeight(ByVal g As Graphics, _ ByVal Value As Object) As Integer Debug.WriteLine("GetPreferredHeight()") Dim NewLineIndex As Integer = 0 Dim NewLines As Integer = 0 Dim ValueString As String = Me.GetText(Value) Do While NewLineIndex <> -1 NewLineIndex = ValueString.IndexOf("r\n", NewLineIndex + 1) NewLines += 1 End While Loop
Return FontHeight * NewLines + yMargin End Function
Protected Overloads Overrides Function GetPreferredSize(ByVal g As Graphics, _ ByVal Value As Object) As Size Dim Extents As Size = Size.Ceiling(g.MeasureString(GetText(Value), _ Me.DataGridTableStyle.DataGrid.Font)) Debug.WriteLine("GetPreferredSize()") Extents.Width += xMargin * 2 + DataGridTableGridLineWidth Extents.Height += yMargin Return Extents End Function Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Source As CurrencyManager, _ ByVal RowNum As Integer) Debug.WriteLine("Paint(1)") Paint(g, Bounds, Source, RowNum, False) End Sub
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Source As CurrencyManager, _ ByVal RowNum As Integer, _ ByVal AlignToRight As Boolean) Debug.WriteLine("Paint(2)" & GetText(GetColumnValueAtRow(Source, RowNum))) Dim Text As String = GetText(GetColumnTextAtRow(Source, RowNum)) PaintText(g, Bounds, Text, AlignToRight) End Sub
Protected Overloads Sub Paint(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Source As CurrencyManager, _ ByVal RowNum As Integer, _ ByVal BackBrush As Brush, _ ByVal ForeBrush As Brush, _ ByVal AlignToRight As Boolean)
Debug.WriteLine("Paint(3)") Dim Text As String = GetText(GetColumnTextAtRow(Source, RowNum)) PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight) End Sub
Protected Overloads Overrides Sub SetDataGridInColumn(ByVal Value As DataGrid) Debug.WriteLine("SetDataGridInColumn()") MyBase.SetDataGridInColumn(Value) If Not (Combo.Parent Is Value) Then If Not (Combo.Parent Is Nothing) Then Combo.Parent.Controls.Remove(Combo) End If End If
If Not (Value Is Nothing) Then Value.Controls.Add(Combo) If Not (tb.Parent Is Value) Then If Not (tb.Parent Is Nothing) Then tb.Parent.Controls.Remove(tb) End If End If
If Not (Value Is Nothing) Then Value.Controls.Add(tb) End Sub
Protected Overloads Overrides Sub UpdateUI(ByVal Source As CurrencyManager, _ ByVal RowNum As Integer, ByVal InstantText As String) Debug.WriteLine("UpdateUI()") Combo.Text = tb.Text If Not (InstantText Is Nothing) Then Combo.Text = InstantText End If End Sub
'---------------------------------------------------------------------- ' Helper Methods '----------------------------------------------------------------------
Public Property ComboBox() As DataGridComboBox Get Return Combo End Get Set(ByVal Value As DataGridComboBox) Combo = Value End Set End Property
Private ReadOnly Property DataGridTableGridLineWidth() As Integer Get If Me.DataGridTableStyle.GridLineStyle = DataGridLineStyle.Solid Then Return 1 Else Return 0 End If End Get End Property
Private Sub EndEdit() Debug.WriteLine("EndEdit()") InEdit = False Combo.Modified = False Invalidate() End Sub
Private Function GetText(ByVal Value As Object) As String If Not Value Is Nothing Then Debug.WriteLine("GetText(" & Value.ToString & ")") Else Debug.WriteLine("GetText(Value is Nothing)") End If If Value Is System.DBNull.Value Then Return NullText
If Not Value Is Nothing Then Debug.WriteLine(Value.ToString) Return Value.ToString Else Debug.WriteLine("Value is Nothing") Return String.Empty End If
End Function
Private Sub HideComboBox() Debug.WriteLine("HideComboBox()") If Combo.Focused Then Me.DataGridTableStyle.DataGrid.Focus() End If Combo.Visible = False End Sub
Private Sub RollBack() Debug.WriteLine("RollBack()") Combo.Text = OldVal tb.Text = OldVal Combo.Modified = False End Sub
Private Sub PaintText(ByVal g As Graphics, _ ByVal Bounds As Rectangle, _ ByVal Text As String, _ ByVal AlignToRight As Boolean)
Debug.WriteLine("PaintText(1)") Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor) Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor) PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight) End Sub
Private Sub PaintText(ByVal g As Graphics, _ ByVal TextBounds As Rectangle, _ ByVal Text As String, _ ByVal BackBrush As Brush, _ ByVal ForeBrush As Brush, _ ByVal AlignToRight As Boolean)
Debug.WriteLine("PaintText(2)" & Text) Dim Rect As Rectangle = TextBounds Dim RectF As RectangleF = RectF.op_Implicit(Rect) ' Convert to RectangleF Dim Format As StringFormat = New StringFormat
If AlignToRight Then Format.FormatFlags = StringFormatFlags.DirectionRightToLeft End If
Select Case Me.Alignment Case Is = HorizontalAlignment.Left Format.Alignment = StringAlignment.Near Case Is = HorizontalAlignment.Right Format.Alignment = StringAlignment.Far Case Is = HorizontalAlignment.Center Format.Alignment = StringAlignment.Center End Select
Format.FormatFlags = Format.FormatFlags Or StringFormatFlags.NoWrap g.FillRectangle(Brush:=BackBrush, Rect:=Rect)
Rect.Offset(0, yMargin) Rect.Height -= yMargin g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format) Format.Dispose()
End Sub
Private Function GetColumnTextAtRow(ByVal Source As CurrencyManager, ByVal RowNum As Integer) As Object Dim value As Object = Me.GetColumnValueAtRow(Source, RowNum) Dim dSource As Object
dSource = Combo.DataSource If value Is System.DBNull.Value Then Return NullText End If If Not dSource Is Nothing Then If TypeOf dSource Is DataTable Then Dim dr As DataRow dSource = CType(dSource, DataTable) If Not dSource.Columns.Contains(Combo.DisplayMember) _ OrElse Not dSource.Columns.Contains(Combo.ValueMember) Then Return NullText End If For Each dr In dSource.Rows If value = dr(Combo.ValueMember) Then Return dr(Combo.DisplayMember) End If Next Return NullText ElseIf TypeOf dSource Is DataView Then Dim drv As DataRowView dSource = CType(dSource, DataView) If Not dSource.Table.Columns.Contains(Combo.DisplayMember) _ OrElse Not dSource.Table.Columns.Contains(Combo.ValueMember) Then Return NullText End If For Each drv In dSource If value = drv(Combo.ValueMember) Then Return drv(Combo.DisplayMember) End If Next Return NullText End If End If End Function
Private Sub Combo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo.SelectedIndexChanged tb.Text = CType(sender, ComboBox).Text End Sub
End Class
End Namespace W
|
Posted by Xander Zelders

What's the Difference between Manual/AutoResetEvent and Monitor?
Found the following interesting discussion in the Newsgroups:
What's the Difference between Manual/AutoResetEvent and Monitor? by:Charles Law
| I've been using monitors a bit lately (some of you may have heard ;-) ) and then up pop Manual and AutoResetEvents , and they look for all the world like the same thing.
Are they interchangeable, or when should I use one over the other?
TIA
Charles
| | | Reply: by:Jay B. Harlow [MVP - Outlook]
| | | Charles, > I've been using monitors a bit lately (some of you may have heard ;-) ) and > then up pop Manual and AutoResetEvents , and they look for all the world > like the same thing. Monitors are used to "synchronize access to a member or to build your own thread management types".
Manual & Auto Reset Events are used to "signaled when an event occurs".
> Are they interchangeable, or when should I use one over the other? Yes they can be used interchangeable, and yes there are times when you should use one over the other. Normally I use SyncLock instead of using the Monitor directly, remember that SyncLock is implemented in terms of Monitor. SyncLock is used to protect one or more blocks of code from being executed simultaneously. For example if I had a System.Collections.Queue to send requests from the Main thread to a Worker thread. I would protect the methods where Queue.Enqueue & Queue.Dequeue were with the same padlock object (the object passed to Monitor/SyncLock).
I would use a Manual or Auto ResetEvent in the same class to let the worker thread know there is work to be done.
Something like:
' untested, typed from memory. Public Class ThreadRequestQueue
Private Readonly m_padlock As New Object Private Readonly m_queue As New Queue Private Readonly m_event As New AutoResetEvent(False)
' called from the Main thread Public Sub AddRequest(ByVal request As Object) SyncLock m_padlock m_queue.Enqueue(Object) End SyncLock m_event.Set() End Sub
' called from the Worker thread Public Function GetRequest() As Object ' Check to see if there are already items available SyncLock m_padlock If m_queue.Count() > 0 Then Return m_queue.DeQueue() End If End SyncLock
' Cannot block worker thread ' while waiting for the main thread to add requests m_event.WaitOne()
' There must be an item SyncLock m_padlock Return m_queue.Dequeue() End SyncLock End Function
End Class
Hope this helps Jay
| | | Reply: by:Charles Law
| | | Hi Jay
> SyncLock is used to protect one > or more blocks of code from being executed simultaneously.
Is this different from "accessing the same variable concurrently"?
What I mean is, if I have
<code> Public Function Read() as Long SyncLock (m_LockObject) Return m_Variable End SyncLock End Function
Public Sub Write(Value As Long) SyncLock (m_LockObject) m_Variable = Value End SyncLock End Sub </code>
can one thread execute Read while another executes Write, so that m_Variable can be read when it is only half updated? After all, I am not executing the same bit of code simultaneously because they are in two different methods.
I understand that two threads cannot execute Read or Write simultaneously, but what about Read *and* Write?
Secondly,
> m_event.Set()
Isn't this just Monitor.Pulse(m_event), and
> m_event.WaitOne()
Monitor.Wait(m_event) ? If so, what is there to choose between the two?
Charles
| | | Reply: by:Jay B. Harlow [MVP - Outlook]
| | | Charles,
Simultaneously and concurrently are synonymous in that only one of either Read or Write will execute at the same time. In other words if I have 2 threads. If Thread 1 is in either Read or Write Thread 2 cannot be in either Read or Write. Like wise if Thread 2 is in either Read or Write, Thread 1 cannot be in either Read or Write. I'm really not sure what you are wanting to say with "*and*".
> Secondly, > > m_event.Set() > Isn't this just Monitor.Pulse(m_event), and > > m_event.WaitOne() > Monitor.Wait(m_event) ?
Go back to the original statement. Monitor can be used "or to build your own thread management types". So yes you can use Monitor to build the two Event classes. I would not be surprised if the two Event classes are implemented in terms of Monitor.
> If so, what is there to choose between the two? One word: Abstraction
As I said before I would use Manual or AutoResetEvent if I wanted to signal an Event between two threads. (notice Event in the name of the class).
I would use Monitor (SyncLock really) to control access to a resource (code block).
Hope this helps Jay
| | | Reply: by:Charles Law
| | | Jay
Thanks for the further clarification.
Charles
|
Posted by Xander Zelders

How do I Overload Show() Method?
Found the following interesting discussion in the Newsgroups:
How do I Overload Show() Method? by:Paul Fairless
| Could someone please explain how I overload the Show() method of a form?
Suppose I select a record from a datagrid on Form1, then I want to show the details of the selected record by opening Form2 using say the CustomerID as an 'argument' to the Show method.
So, in Form1 I would have code such as:
Sub GetSelectedRecord() Form2.Show(CustomerID) Me.Close() End Sub
.... and in Form2 I woudl have code such as:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ..... code to read a record from a database using the CustomerID End Sub
Many Thanks
Paul.
| | | Reply: by:Armin Zingler
| | | Private m_IDCustomer As Integer
Public Overloads Sub Show(ByVal IDCustomer As Integer) m_IDCustomer = IDCustomer 'you can place the "code to read a record from a database using the" 'here or in the load event.
MyBase.Show() End Sub
-- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
|
Posted by Xander Zelders

How to find Dialog
Found the following interesting discussion in the Newsgroups:
Find Dialog by:Anonymous
| I'm trying to create a find dialog box and I need to understand this part of .NET (I am an experienced vb6 programmer): - How do i create a variable that can be accessed and modified on two forms? I tried public variables in a module, but they didn't seem to work. - How can I do something like (in vb6) frmMain.txtMain.Text = "HI" . I have searched and searched an I can't understand how to do this!
Thanks!
| | | Reply: by:Anonymous
| | | I am so sorry - every time i sent this it created an error so i assumed that it didn't work! I didn't mean for three messages to come up! Sry!
|
Posted by Xander Zelders

How to find Dialog
Found the following interesting discussion in the Newsgroups:
Find Dialog by:Anonymous
| I'm trying to create a find dialog box and I need to understand this part of .NET (I am an experienced vb6 programmer): - How do i create a variable that can be accessed and modified on two forms? I tried public variables in a module, but they didn't seem to work. - How can I do something like (in vb6) frmMain.txtMain.Text = "HI" . I have searched and searched an I can't understand how to do this!
Thank you!
| | | Reply: by:Cor Ligthert
| | | Hi Newto,
> I'm trying to create a find dialog box and I need to understand this part of .NET (I am an experienced vb6 programmer):
Make a form and than you can use dim frmdialog as new form2 myvars.myproperty = something 'see below frmdialog.showdialog (you can also test the return value with this) frmdialog.dispose
And on Form2 in the load event when you use it as above mytextbox.text = myvars.myproperty
> - How do i create a variable that can be accessed and modified on two forms? I tried public variables in a module, but they didn't seem to work. The above method should work, however the nicest way is \\public class myvars Private Shared mVar As String Public Shared Property myproperty() As String Get Return (mVar) End Get Set(ByVal Value As String) mVar = Value End Set End Property End Class ///
> - How can I do something like (in vb6) frmMain.txtMain.Text = "HI" . I have searched and searched an I can't understand how to do this!
And than the easy one me.text = "HI"
I hope this helps?
Cor
|
Posted by Xander Zelders

How to create a Find Dialog
Found the following interesting discussion in the Newsgroups:
Creating a Find Dialog by:Anonymous
| Hi, I am trying to create a find Dialog box for my notepad "test" application, to help me learn .NET (I am an experienced vb6 programmer). How do I create variables that are available on all forms (vb6 public) and how to I do something like: frmMain.rtfText.SelectionLength = 13 without reloading frmMain? So far, I have only been able to set parts of a form before loading it in .NET.
Thanks!
| | | Reply: by:Sahil Malik
| | | You are gonna love .NET compared to VB6.
Though it is a bit different to get used to. The find dialog box is implemented as nothing but ... guess what .. yet another class.
So if your callee is frmMain, and your called is dlgFind
you could from frmMain say .. dlgFindInstance.VariableName (assuming VariableName is public) OR from dlgFind, you could in it's contructor pass an instance of frmMain, which can access it's variables properties etc, or you could go the this.Parent (C#) route instead. VB.NET I guess is Me.parent or sump'n like dat. :)
- Sahil Malik Independent Consultant You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/
| | | Reply: by:Cor Ligthert
| | | Hi New
I answered it above, however your last question is different.
A form is a class, and a class you can name by me. What I wrote in your other message for "text" is for every methode or property the same for a class. "me.whatever?
I hope this helps?
Cor
|
Posted by Xander Zelders

Odd Format issue
Found the following interesting discussion in the Newsgroups:
Odd Format issue by:Anonymous
| I am having the following problem with format which is just very odd.
dim sSSN as string = "011-11-2222" sSSN = strings.format(sSSN, "###-##-####") console.write(sSSN)
this returns "###-##-####"
so to get around that I try sSSN = strings.format(val(sSSN), "###-##-####")
needless to say I lose the leading 0 is the SSN.
I've worked around it but there just has to be an easier way, anyone have any ideas?
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | What would you expect?
-- Herfried K. Wagner [MVP]
| | | Reply: by:Anonymous
| | | I'm sorry the code should have looked like dim s as string 011223333
and I would have expected this line console.write(strings.format(s, "###-##-####")
to return "011-22-3333"
however it does not it returns "###-##-####", I guess my question is why doesn't format work on strings. The # input is suppose to accept numeric chars right?
It just seems that without some trickery there is no way to get that format from that string. I thought there may have been an easier way.
| | | Reply: by:Armin Zingler
| | | What do you want to format? "011-11-2222" has already the right format. -- Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
|
Posted by Xander Zelders

Can't FindControl in DataGrid
Found the following interesting discussion in the Newsgroups:
Can't FindControl in DataGrid by:Jim Bayers
| I get this error:
System.NullReferenceException: Object reference not set to an instance of an object.
And this is the subroutine that throws it: Protected Sub DataUpdate(ByVal Sender As Object, _ ByVal E As DataGridCommandEventArgs)
Label1.Text = CType(E.Item.FindControl("DropDownList1"), DropDownList).SelectedItem.Text
' Save TempValue to DB End Sub
The dropdownlist is in a datagrid template:
<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" oncancelcommand="DataCancel" onupdatecommand="DataUpdate" datakeyfield="tourdate" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Horizontal" oneditcommand="DataEdit"> <Columns> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn> <asp:TemplateColumn HeaderText="EditColumn"> <ItemTemplate> <asp:Label id=Label2 runat="server" Text='<%# Container.DataItem("tourdate") %>'>Label </asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id=DropDownList1 runat="server" DataSource="<%# dbView %>" DataTextField="tourDate" DataMember="spTours" DataValueField="id"> </asp:DropDownList> </EditItemTemplate> </asp:TemplateColumn> <asp:BoundColumn DataField="tourDate" HeaderText="Date"></asp:BoundColumn> </Columns> </asp:datagrid>
Everything else is working, the datagrid shows the data. The dropdown box is populated. I can pick a value. But when I click the update link on the datagrid, it throws the error.
| | | Reply: by:Jim Bayers
| | | I changed it to:
Sub UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand Dim ddl As New DropDownList() ddl = e.Item.FindControl("DropDownList1") Label1.Text = ddl.SelectedItem.Text End Sub and I get the same error:
System.NullReferenceException: Object reference not set to an instance of an object.
|
Posted by Xander Zelders

How to compare IntPtr's
Found the following interesting discussion in the Newsgroups:
Compareing IntPtr's by:Brian Henry
| how would you compare an IntPtr to check if it is zero?
c++ example of what i want to do IntPtr hWndMdiClient; If (hWndMdiClient != IntPtr.Zero) {...}
thanks
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | \\Dim p1 As IntPtr = New IntPtr(23234) Dim p2 As IntPtr = New IntPtr(23234) Dim p3 As IntPtr = New IntPtr(99) MsgBox(p1.Equals(p2).ToString()) MsgBox(p1.Equals(p3).ToString()) ///
-->
\\If p1.Equals(IntPtr.Zero) Then ... End If ///
-- Herfried K. Wagner [MVP]
| | | Reply: by:Brian Henry
| | | thanks that worked good
| | | Reply: by:Mick Doherty
| | | Dim hWndMdiClient as IntPtr If Not hWndMdiClient.Equals(IntPtr.Zero) Then .... End If
-- Mick Doherty http://homepage.ntlworld.com/mdaudi100/alternate/home.html
Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
|
Posted by Xander Zelders

exhausted all avenues
Found the following interesting discussion in the Newsgroups:
exhausted all avenues by:I'm spent
| Does anyone know how to accept all certificates when a site is browsed to through the axwebbrowser in a windows application?
Thanks.
| | | Reply: by:scorpion53061
| | | Imports System Imports System.IO Imports System.Net Imports System.Threading Imports System.Text.RegularExpressions Imports System.Text.Encoding Imports System.Security.Cryptography.X509Certificates
Public Class TrustAllCertificatePolicy Implements System.Net.ICertificatePolicy Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) _ As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult Return True End Function End Class Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click 'Create(a) 'WebRequest' object with the specified url System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy
Dim myWebRequest As WebRequest 'myWebRequest.Credentials = myCert.TrustAllCertificatePolicy myWebRequest = WebRequest.Create("https://sentri.us.nortel.com:8443/SENTRI/home.jsp")
' Send the 'WebRequest' and wait for response. Dim myWebResponse As WebResponse myWebResponse = myWebRequest.GetResponse() ' Call method 'GetResponseStream' to obtain stream associated with the response object Dim ReceiveStream As Stream ReceiveStream = myWebResponse.GetResponseStream()
Dim encode As System.Text.Encoding encode = GetEncoding("utf-8")
' Pipe the stream to a higher level stream reader with the required encoding format. Dim readStream As New StreamReader(ReceiveStream, encode) 'txtLog.Text = (ControlChars.CrLf + "Response stream received") Dim read(1024) As [Char]
' Read 256 charcters at a time . Dim count As Integer = readStream.Read(read, 0, 1024) txtLog.Text = "" 'While count > 0 While readStream.Peek >= 0
' Dump the 256 characters on a string and display the string onto the console. Dim str As New [String](read, 0, count) txtLog.Text = txtLog.Text & (str) count = readStream.Read(read, 0, 1024)
End While Dim str2 As New [String](read, 0, count) txtLog.Text = txtLog.Text & (str2) count = readStream.Read(read, 0, 1024) 'Console.WriteLine("")
' Release the resources of stream object. readStream.Close()
' Release the resources of response object. myWebResponse.Close()
End Sub
| | | Reply: by:Im Spent
| | | Thanks for the reply.
I have a couple of questions?
1. What type is the txtLog variable (it's declaration is not specified in the code)?
2. I know that reading from the response stream gives the html that the browser renders as a webpage, but how do I send it to the axwebbrowser?
The websites I am navigating to are ASP pages that have controls on them that I need to be able to use once the page is rendered in the axwebbrowser.
Thanks again!!
| | | Reply: by:scorpion53061
| | |
It appears to be a textbox or an object that has a text property of some kind.
I would look for a substring or indexof within the string and when found lock on to it with a variable and send as you need to.
|
Posted by Xander Zelders

How to load Help File in VB.NET
Found the following interesting discussion in the Newsgroups:
Loading Help File in VB.NET by:Pug Fugly
| I have a .chm file that I have added to my project. The "Build Action" of the file is set to "Content". I am trying to use Help.ShowHelp() to load the file but it only seems to work if I use a full file path and not a relative one. I get the following error "Invalid URI: The format of the URI could not be determined." If I click on "Continue" in the debugger, the file loads after that exception. Using a full path (ie. "c:\folder\test.chm") works fine without the exception, but something like "/Global/Help/test.chm" does not. Any idea why? I have tried switching the slashes but it didn't seem to work.
Thanks, Pug
| | | Reply: by:Paul Clement
| | | Don't believe relative paths are supported. I would work off the application assembly path or a special folder path. Paul ~~~ pclement@ameritech.net Microsoft MVP (Visual Basic)
|
Posted by Xander Zelders

VB.NET DLLs and ProgIDs
Found the following interesting discussion in the Newsgroups:
VB.NET DLLs and ProgIDs by:eliasengin@msn.com (eli)
| please...somebody answer this question.lol I have submit it to 4 forums and it seems noone can answer it.
In VB6 I had made a standard windows application (client) and a DLL (server). The client had a reference to AutoCAD application (you dont have to know AutoCAD, I just made a reference to its interface thats all). Then I could use a function of AutoCAD's interface call GetInterfaceObject(<ProgID>). Giving to the function the ProgID of my DLL's project I was able to load the DLL in memory space of AutoCAD.
Now, coming to .NET world, I created the same DLL and client application in VB.NET. But Calling my GetInterfaceObject function with the DLL's project ProgID as I used to, doesn't work.
Can anyone help what is going on? Is it because something has changed with the ProgID thing? Is it because DLLs are not registered any more?
Thanks in advance, Elias
I want to move a big application to VB.NET and I can't due to this problem
| | | Reply: by:Mattias Sjögren
| | | >I have submit it to 4 forums and it seems noone can answer it.
Perhaps because you don't supply enough information. Have you registered your library correctly? Can you instantiate objects from other COM clients? DO you get any error messages?
Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
| | | Reply: by:eliasengin@msn.com (eli)
| | | Maybe you are righ, I dont provide enough information.
Can I register DLLs with VB.NET? I thought it was something abandoned. And if I can isnt it automatically done any more to my machine? (as I develop, like VB6?) And if it is like that will that be done in my clents machine at distribution?
The case is really simple:
I have a variable "application" with which I reference my AutoCAD application And a "server" variable with which I reference my DLL reference (I added a reference to my DLL from the references dialogbox).
Then I can write set Server=application.GetInterfaceObject(ProgID of the DLL project). The function finds the ProgID and works in VB6 fine. I can figure out what changes in .NET, but I guess the ProgID is not acceptable anymore.
(I dont remember right now the error message I get and I am away from my computer, but I can give it to you later)
Thank you very much for answering. I hope I did provide you with some extra important info
Elias
|
Posted by Xander Zelders

How to copy selected items in listbox to windows clipboard
Found the following interesting discussion in the Newsgroups:
Copy selected items in listbox to windows clipboard by:Anonymous
| Hi, All, I am working with a listbox in VB .Net and would like the listbox to have the following function: when I press "Ctrl-C", the selected item on the ListBox is copied to the clipboard.
Thanks in advance for the help
| | | Reply: by:Anonymous
| | | Public Class myListBox Inherits System.Windows.Forms.ListBox
#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New()
'This call is required by the Windows Form Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub
'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub
#End Region
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _ ByVal keyData As System.Windows.Forms.Keys) As Boolean If keyData = Keys.Control + Keys.C Then 'Copy something to ClipBoard
End If End Function End Class
|
Posted by Xander Zelders

How to navigate the records and binding it to text box
Found the following interesting discussion in the Newsgroups:
Navigating the records and binding it to text box by:madhu_09@hotmail.com (madhu)
| Hello all,
I am a bignner to vb.net
I am not able to move the dataset and bind the textbox to dataset. My objective is 1) when the form loads it should display the first record. and the user should be able to move next and move previous and move last and move first . 2) Binding the textbox to the dataset what is the equivlant of text1.text = rs.fields("subject_id") in vb.net 3) What is the best method of opening the connection and sqldataset , sqlcommand
Here is the code where i get an error in the binding.
Form_load
Dim conn As New SqlConnection Dim cmdSubjects As New SqlCommand Dim dsSubjects As New DataSet Dim daSubjects As New SqlDataAdapter Dim StrSQL As String Dim SQL_Connection_String As String SQL_Connection_String = "Server=myserver; DataBase=my_testdb; Integrated Security=SSPI"
StrSQL = "Select * from Subjects"
conn = New SqlConnection(SQL_Connection_String) conn.Open() cmdSubjects = New SqlCommand(StrSQL, conn)
dsSubjects = New DataSet
daSubjects = New SqlDataAdapter(StrSQL, conn) daSubjects.Fill(dsSubjects, "Subjects")
DataGrid1.DataSource = dsSubjects.Tables!Subjects TextBox1.DataBindings.Add ("Text", dsSubjects.Tables!Subjeects, "Subject_ID") (i get the error at this point)
End sub Thank in advance. Please mail to madhu_09@hotmail.com or madhu_09@yahoo.com
From madhu
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
Use the currency manager to navigate records. Here is a simple example. http://www.onteorasoftware.com/downloads/navigaterecords.zip
Ken
Outgoing mail is certified Virus Free. Checked by AVG Anti-Virus (http://www.grisoft.com). Version: 7.0.230 / Virus Database: 263.3.0 - Release Date: 6/12/2004
|
Posted by Xander Zelders

How to change design in excel from VB.NET
Found the following interesting discussion in the Newsgroups:
changing design in excel from VB.NET by:Tomek
| Hi, Please help me with this. I'm exporting data to excel file and I want to customize its apperance (i.e. bold columns name, auto size colums width, freeze some columns). Is it possible? Thanks in advance, Tomek
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | Yes, but I suggest to ask that question in the Excel VBA group:
<URL:news://news.microsoft.com/microsoft.public.excel.programming>
-- Herfried K. Wagner [MVP]
| | | Reply: by:Tomek
| | | Hmm, I'm asking how to do it from Visual Basic .NET not from VBA. It is easy to do it in Excel but I want to do it from my VB.NET application. Tomek
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | If you know how to do it in Excel VBA, it's easy to implement in VB.NET.
-- Herfried K. Wagner [MVP]
| | | Reply: by:scorpion53061
| | | IT is most certainly possible.
|
Posted by Xander Zelders

CommandBuilder.Dispose - should I use it?
Found the following interesting discussion in the Newsgroups:
CommandBuilder.Dispose - should I use it? by:Ed
| I just learned how to use the Commandbuilder and have researched it a little bit further and see that there is a dispose property. Should this be used after invoking the command builder or does vb.net cleanup after itself on its own? If I don't use it would this lead to a memory leak?
TIA, Ed
| | | Reply: by:Sahil Malik
| | | This brings up a vast topic of "How memory handling works in .NET".
First of all - try not to use CommandBuilder, it's not the recommended approach unless your application is aimed to be quick and dirty.
Secondly - Dispose is thanks to IDisposable, all expensive objects must implement dispose. Calling dispose will immediately ask the object to clean itself. The other option is Finalize - which is well equal to the destructor with a difference that you donot know when it will be called. It is eventually called by the garbage collector, but you don't know when that will happen and you cannot determine that with any degree of certainity.
Therefore, if an object exposes a dispose - call it when ur done with it.
Will not calling it result in a memory leak? It could .. though restarting ur app will fix that to some extent and call the finalizers on each of the objects, but thats not good either.
- Sahil Malik Independent Consultant You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/
| | | Reply: by:Ed
| | | Thanks for your reply. Someone suggested I could use the commandbuilder for the InsertCommand of the dataAdapter object. My issue is/was that I felt I was writing too many line of code for sqlParameters for the InsertCommand.
sqlParm = sqlDa.Parameters(New SqlParameter("@fld0", Nvarchar (50), "fld0") .... sqlParm = sqlDA.Parameters(New SqlParameter("@fld40",...) ....
The commandBuilder looked/looks quite appealing instead of writing a bunch of extra lines of code as above.
So I suppose it would be a good idea to call Dispose when I am done inserting data.
Thanks, Ed
| | | Reply: by:Cor Ligthert
| | | Hi Ed,
When your programs have no troubles why would you not use the commandbuilder, it has bugs however there are more parts in dotNet which have bugs, so should that mean you should not use them. (The most terrible one with bugs is that nice control the combobox). Therefore you should test every program again and again.
The dispose should be used when there are unmanaged resources.
There are texts to use it always when it is implemented as a method, because there is nothing wrong to do that. That is for me the same sentence as that it does nothing wrong to set every value to zero before you close your program. A lot of dispose are in a classes because it comes from a derived class as the component class. (By instance every label has it).
Really separatly adviced it is with: When you implements unmanaged resources in your classes. Bitmaps Dialogforms Connections with more than 100 connections on a network (instead of close, the dispose is here removing the connection string and probably something extra in that method what is not dispose, however used by the devellopers to reset the connectionpool).
I hope this helps?
Cor
|
Posted by Xander Zelders

Help and ideas appreciated
Found the following interesting discussion in the Newsgroups:
Help and ideas appreciated by:Anonymous
| Hi,
I'm sorry if I'm in the wrong forum (last time I looked VB online forums had different topics), if this is the case could you please redirect me to another one suitable for my problem? I would like to write a VB application (under excel), which can read character strings from a predefined place (eg. row1 column1-row1 column 25) in text file and write them to a specific cell. I would also like to have my program work backwards, read specific cells in excel and then write contents to specific places in a text file (and create the text file). Thanks in advance
| | | Reply: by:Cor Ligthert
| | | Hi Baranya,
Yes you are in the wrong newsgroup. You should look for this in an office developper newsgroup, here you get probably not the best answers on your question (I wrote probably because this is a newsgroup with a lot of clever guys/girls).
However some links for Excel developping.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;311452
http://msdn.microsoft.com/office/
Pia Download http://www.microsoft.com/downloads/details.aspx?FamilyID=c41bd61e-3060-4f71-a6b4-01feba508e52&displaylang=en
I hope this helps?
Cor
|
Posted by Xander Zelders

How to print to Generic Printer
Found the following interesting discussion in the Newsgroups:
Printing to Generic Printer by:Rob T
| I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a system call is too small".
I found the following article, that I assume is similar to my problem, which is of little help: http://support.microsoft.com/default.aspx?scid=kb;en-us;822779
Any suggestions?
Thanks. -Rob T.
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | Post the code you are using to print to the printer.
-- Herfried K. Wagner [MVP]
| | | Reply: by:Rob T
| | | It's the code taken right from the MSDN example. Try it...if you install a generic printer (or print to a file as generic) it will fail. ;-)
Public Class PrintingExample Private printFont As Font Private streamToPrint As StreamReader Private Shared filePath As String
Public Sub New() Printing() End Sub
' The PrintPage event is raised for each page to be printed. Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs) Dim linesPerPage As Single = 0 Dim yPos As Single = 0 Dim count As Integer = 0 Dim leftMargin As Single = ev.MarginBounds.Left Dim topMargin As Single = ev.MarginBounds.Top Dim line As String = Nothing
' Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
' Iterate over the file, printing each line. While count < linesPerPage line = streamToPrint.ReadLine() If line Is Nothing Then Exit While End If yPos = topMargin + count * printFont.GetHeight(ev.Graphics) ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _ yPos, New StringFormat()) count += 1 End While
' If more lines exist, print another page. If Not (line Is Nothing) Then ev.HasMorePages = True Else ev.HasMorePages = False End If End Sub
' Print the file. Public Sub Printing() Try streamToPrint = New StreamReader(filePath) Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() AddHandler pd.PrintPage, AddressOf pd_PrintPage ' Print the document. pd.Print() Finally streamToPrint.Close() End Try Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 'Printing
' This is the main entry point for the application. Public Shared Sub Main() Dim args() As String = System.Environment.GetCommandLineArgs() Dim sampleName As String = args(0) If args.Length <> 1 Then Console.WriteLine("Usage: " & sampleName & " <file path>") Return End If filePath = args(0) End Sub End Class
[C#] public class PrintingExample { private Font printFont; private StreamReader streamToPrint; static string filePath; public PrintingExample() { Printing(); }
// The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; String line=null;
// Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line. while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; }
// If more lines exist, print another page. if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; }
// Print the file. public void Printing() { try { streamToPrint = new StreamReader (filePath); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); // Print the document. pd.Print(); } finally { streamToPrint.Close() ; } } catch(Exception ex) { MessageBox.Show(ex.Message); } }
// This is the main entry point for the application. public static void Main(string[] args) { string sampleName = Environment.GetCommandLineArgs()[0]; if(args.Length != 1) { Console.WriteLine("Usage: " + sampleName +" <file path>"); return; } filePath = args[0]; new PrintingExample(); }
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | I remember I posted this link some days ago...
HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET <URL:http://support.microsoft.com/?scid=kb;EN-US;322090>
-- Herfried K. Wagner [MVP]
| | | Reply: by:Rob T
| | | Thanks. This seems like a complex way to simply print some raw data. I'm curious to find how Microsoft print their 'test page' in the printer properties... I would have thought that they would have just stripped out the graphics and printed the text......
|
Posted by Xander Zelders

CertificatePolicy
Found the following interesting discussion in the Newsgroups:
CertificatePolicy by:Susan
| My windows application contains a browser, which is used to browse to HTTPS sites. The Security Alert dialog comes up stating that the name on the certificate doesn't match the name of the site. I have implemented a CertificatePolicy that accepts all certificates by always returning true, but the browser is using or getting access to this policy. The Security Alert is still appearing.
Code:
'My class to override the existing Certificate Policy 'Accepts all certificates Public Class AcceptAllPolicy Implements System.Net.ICertificatePolicy
Public Function CheckValidationResult(ByVal srvPoint _ As ServicePoint, ByVal cert As X509Certificate, ByVal _ request As WebRequest, ByVal certificateProblem As _ Integer) As Boolean Implements _ ICertificatePolicy.CheckValidationResult
Return True
End Function End Class
'The axwebbrowser uses the navigate() or navigate2() 'method to access the site. I have implemented the 'following code when the site is to be navigated to
System.Net.ServicePointManager.CertificatePolicy = New AcceptAllPolicy()
webBrowser.show() webBrowser.navigate(<https site>)
Any ideas/help/comments/suggestions?
Thanks!!
| | | Reply: by:scorpion53061
| | | Imports System Imports System.IO Imports System.Net Imports System.Threading Imports System.Text.RegularExpressions Imports System.Text.Encoding Imports System.Security.Cryptography.X509Certificates
Public Class TrustAllCertificatePolicy Implements System.Net.ICertificatePolicy Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) _ As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult Return True End Function End Class Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click 'Create(a) 'WebRequest' object with the specified url System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy
Dim myWebRequest As WebRequest 'myWebRequest.Credentials = myCert.TrustAllCertificatePolicy myWebRequest = WebRequest.Create("https://sentri.us.nortel.com:8443/SENTRI/home.jsp")
' Send the 'WebRequest' and wait for response. Dim myWebResponse As WebResponse myWebResponse = myWebRequest.GetResponse() ' Call method 'GetResponseStream' to obtain stream associated with the response object Dim ReceiveStream As Stream ReceiveStream = myWebResponse.GetResponseStream()
Dim encode As System.Text.Encoding encode = GetEncoding("utf-8")
' Pipe the stream to a higher level stream reader with the required encoding format. Dim readStream As New StreamReader(ReceiveStream, encode) 'txtLog.Text = (ControlChars.CrLf + "Response stream received") Dim read(1024) As [Char]
' Read 256 charcters at a time . Dim count As Integer = readStream.Read(read, 0, 1024) txtLog.Text = "" 'While count > 0 While readStream.Peek >= 0
' Dump the 256 characters on a string and display the string onto the console. Dim str As New [String](read, 0, count) txtLog.Text = txtLog.Text & (str) count = readStream.Read(read, 0, 1024)
End While Dim str2 As New [String](read, 0, count) txtLog.Text = txtLog.Text & (str2) count = readStream.Read(read, 0, 1024) 'Console.WriteLine("")
' Release the resources of stream object. readStream.Close()
' Release the resources of response object. myWebResponse.Close()
End Sub
|
Posted by Xander Zelders

Object in textbox.text
Found the following interesting discussion in the Newsgroups:
object in textbox.text by:Frank
| Hello, I use the tag of a textbox to store the address of a structure: uFormTag = New formTag()
Me.Tag = uFormTag
First question: is that the rigth way to do it? Or should it be
tag=addressof uformtag
Second question: how do I pull the info out of the tag? How do I use the address in there to get to the info in the structure?
Thanks
Frank
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
Use Me.Tag = uFormTag.
To retrieve Dim uFormTag as FormTag = Directcast(me.tag,FormTag) Ken
Outgoing mail is certified Virus Free. Checked by AVG Anti-Virus (http://www.grisoft.com). Version: 7.0.230 / Virus Database: 263.3.0 - Release Date: 6/12/2004
| | | Reply: by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])
| | | \\Me.Tag = uFormTag ///
If the type of 'uFormTag' is a structure (value type), a copy of the "object" will be created. If you want to assign a reference, use a class instead of the structure.
> Second question: how do I pull the info out of the tag? How do I use the > address in there to get to the info in the structure?
\\foo = DirectCast(Me.Tag, Goo) ///
.... assuming 'Goo' is the type of the object assigned to 'Me.Tag'.
-- Herfried K. Wagner [MVP]
|
Posted by Xander Zelders

Problem with converting code...
Found the following interesting discussion in the Newsgroups:
Problem with converting code... by:Brian Henry
| Hi,
I am looking at the project at http://vbaccelerator.com/home/NET/Code/Libraries/Windows/MDI_Client_Area_Painting/article.asp and i'm trying to convert it to VB.net
right now im in the file MDIClientWindow.cs and the following but of code does not work...
#Region "EnumWindows Code"
Private Sub GetWindows(ByVal hWndParent As IntPtr)
Me.UnManagedMethods.EnumChildWindows(hWndParent, New EnumWindowsPro |
| |