List(T).RemoveAll(match as System.predicate) Remove from IEnumerable possibly based on match

Useful
Would encourage more use of List(of )

http://msdn.microsoft.com/en-us/library/wdka673a.aspx

“Input String was not in the correct format” – on Bindingsource

Check all textbox or other controls with bindings.
Did you set the value of one programmatically to wrong format. E.g. Number binding, but text put in.
Bindingsource row will remain rowstate.detached until resolved.

Changing Settings at Runtime in working project and referenced assemblies (or projects) ( including connection strings )

 
I like and need this.
 
Put this in ApplicationEvents
 

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
    SetConnectionStrings()
End Sub

 

Private Sub SetConnectionStrings()

            Dim sConString As New SqlConnectionStringBuilder
            sConString.MultipleActiveResultSets = True
            sConString.IntegratedSecurity = True

            Select Case My.Computer.Name.ToUpper
                Case “Computer1”
                    sConString.DataSource = My.Computer.Name
                Case “Computer2”
                    sConString.DataSource = My.Computer.Name ‘+ “\SQLEXPRESS”
                Case Else
                    sConString.DataSource = “<your server name>”
            End Select

            My.Settings.conStringSettings = New System.Configuration.ConnectionStringSettings
            My.Settings.conStringSettings.ProviderName = System.Data.SqlClient 

            sConString.InitialCatalog = “<your initial catalog>”
            My.Settings.<name of saved system.configuration.connectionstringsettings>.ConnectionString = sConString.ConnectionString
            My.Settings(<name of saved connection setting) = sConString.ConnectionString
            Global.<referenced assembly name>.My.MySettings.Default(“<name of saved connection setting>”) = sConString.ConnectionString
            ‘MessageBox.Show(Global.BC.My.MySettings.Default.conStrSOP)

End Sub

 

Late Binding e.g. to Office, Excel, Word etc

 
Option Strict Off
‘Early binding would require COM reference to Excel which brings in
‘   Microsoft.Office.Core
‘   Microsoft.Office.Interop.Excel
‘Imports Microsoft.Office.Interop
‘However late binding requires Option Strict Off
 
Public Class cls
    Private Sub CopyClipboardToExcel(Optional ByVal MyNewFileName As String = "")
        ‘Late Binding or distribute reference
        ‘http://msdn.microsoft.com/en-us/library/0tcf61s1.aspx
        Try
            ‘Dim xlApp As Excel.Application
            Dim xlApp As Object = CreateObject("Excel.Application")
            Dim xlBook As Object = xlApp.Workbooks.Add
            Dim xlSheet As Object = xlBook.Worksheets(1)
            xlSheet.Range("A1").Select()
            xlSheet.Paste()
            Call FormatExcelSheet(xlApp)
            ‘xlSheet.Cells(2, 2) = "This is column B row 2"
            xlSheet.Application.Visible = True
            If MyNewFileName <> "" Then
                xlSheet.SaveAs(MyNewFileName)
                ‘ Optionally, you can call xlApp.Quit to close the workbook.
            End If
        Catch ex As Exception
            If IsT1 Then
                Throw New ApplicationException(ex.Message, ex)
            End If
        End Try
    End Sub
End Class
 

Object binding to a BindingSource (and probably a DataGridView) – Add New Item

 

Private Sub DecisionBindingSource_AddingNew(ByVal sender As System.Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles DecisionBindingSource.AddingNew

Try
Dim dNew As New Decision
dNew.DateInput = Today
dNew.IsNew = True
dNew.StatusID = Decision.StatusIDEnum.Current

'Lambda
Dim dList As IList(Of Decision) = CType(DecisionBindingSource.DataSource, IList(Of Decision))
dNew.ID = dList.Max(Function(d) d.ID) + 1
e.NewObject = dNew

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Lambda VB.Net Max

 

‘Lambda

Dim dList As IList(Of Decision) = CType(DecisionBindingSource.DataSource, IList(Of Decision))
dNew.ID = dList.Max(
Function(d) d.ID) + 1

Talking about How to: Bind Windows Forms Controls to DBNull Database Values

How to: Bind Objects to Windows Forms DataGridView Controls

 

Taken from MSDN Link Here but adjusted to make abstract

Private Sub SetupDGVComboBoxToEnum()
SetupDGVComboBoxColumnToEnumType(GetType(Decision.StatusIDEnum))
DGVColumnStatusID.DataPropertyName = "StatusID"
DGVColumnStatusID.Name = "Status"
End Sub

Private Sub SetupDGVComboBoxColumnToEnumType(ByVal enumType As Type)
DGVColumnStatusID.DataSource = [Enum].GetValues(enumType)
End Sub

Most Recently Used for objects on a form

 
Probably other ways of doing this. However this is my quickly devised method. Using a MRUToolStripDropDownButton.
Need to call MRUAdd after loading an object


Private mruList As IList(Of T)

Private Sub MRUAdd()
If mruList.Contains(Me.cPadMain) Then
mruList.Remove(Me.cPadMain)
End If

'Lambda
If mruList.Where(Function(m) m.ID = cPadMain.ID).Count = 0 Then
mruList.Insert(0, Me.cPadMain)
End If
MRUDisplay()

End Sub


Private Sub MRUDisplay()
MRUToolStripDropDownButton.DropDownItems.Clear()

'LINQ
Dim MRU As IEnumerable(Of PadMain) = From pm In mruList Order By pm.PadMaterial Descending
For Each pm As PadMain In MRU
Dim tsi As New ToolStripMenuItem
tsi.Tag = pm.ID
tsi.Text = pm.Pad + " in " + pm.Material.Material + " " + pm.ID.ToString
MRUToolStripDropDownButton.DropDownItems.Insert(0, tsi)
If MRUToolStripDropDownButton.DropDownItems.Count > 10 Then
Exit For
End If
Next

End Sub

LINQ samples

To use LINQ need

Imports System.Linq
May need reference to System.Core and System.Data
‘LINQ
Dim MRU As IEnumerable(Of PadMain) = From pm In mruList OrderBy pm.PadMaterial

LINQ to Entity Framework

Private
context As BC.SWT.EntityModel.SOPEntities

Dim EntityConnectionString = Configuration.ConfigurationManager.ConnectionStrings(“SOPEntities”).ConnectionString
context = New BC.SWT.EntityModel.SOPEntities(EntityConnectionString)

Dim
CustomerQuery AsObjectQuery(OfCustomer) = context.Customers
Dim results = From a In CustomerQuery Select a.CustomerID, a.Customer1 OrderBy Customer1