Sunday, 30 December 2018

Auto start vb.net application

Start a vb.net application on windows startup or load.

Just Copy and Paste Below code in Startup Form.
(Startup Form : From where application start or that form which open/display first while launching application)



Public Sub RunAtStartup(ByVal ApplicationName As String, ByVal ApplicationPath As String)
Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
With CU
.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
.SetValue(ApplicationName, ApplicationPath)
End With
End Sub


Then copy below code to form load event

RunAtStartup(Application.ProductName,Application.ExecutablePath)


Saturday, 24 November 2018

Start software on startup of Window / how to make software start on startup

How to make software start on startup ? OR

Start software on startup of Window

Step : 1 : Press Window Key + R  
Its open Run Window, And Write  "shell:startup" and press ok


Step : 2 : After Pressing ok, Start Up window  will open

Step : 3 : Whatever software or Program want to start at starting of window just copy and past shortcut of that software here (i.e. at Start Up window)
For example I Want to start Ms Word at starting up of window i Just copy and Past shortcut 

Watch Vidiio


Tuesday, 6 November 2018

Visual Studio Crystal Report Error

Error Description:

FileNotFoundException was Unhandled

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 


Its too much easy.
Just Copy Paste below code to "App.config" file

<startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
 </startup>

Tuesday, 12 June 2018

DataGridView : disable the column header sorting

VB.NET
 For Each column As DataGridViewColumn In DataGridView1.Columns
            column.SortMode = DataGridViewColumnSortMode.NotSortable
 Next


C#
foreach (DataGridViewColumn column in DataGridView1.Columns)
{
    column.SortMode = DataGridViewColumnSortMode.NotSortable;
}

Sunday, 10 June 2018

Copy Datagridview data to another Datagridview

The following is for VS2008 or higher. Place the code below into a code module, not a form or class.

<System.Runtime.CompilerServices.Extension()> _
Public Sub CloneRowWithValues(ByVal SingleRow As DataGridViewRow, ByVal Target As DataGridView)
    Dim Results As DataGridViewRow = CType(SingleRow.Clone(), DataGridViewRow)
    For Row As Int32 = 0 To SingleRow.Cells.Count - 1
        Results.Cells(Row).Value = SingleRow.Cells(Row).Value
    Next
    Target.Rows.Add(Results)
End Sub
-------------------------------------------------------------------------------------------------------------------------

Usage on the current row of DataGridView1 to add it to DataGridView2. Both DataGridView controls must have the same columns.

DataGridView1.CurrentRow.CloneRowWithValues(DataGridView2)

-------------------------------------------------------------------------------------------------------------------------
For copying all rows from DataGridView1 to DataGridView2
For Each row As DataGridViewRow In DataGridView1.Rows
    row.CloneRowWithValues(DataGridView2)
Next

 -------------------------------------------------------------------------------------------------------------------------
Another idea, you set a DataTable as the DataSource of a BindingSource component and set the DataSource of a DataGridView to the BindingSource. Now select some rows in the DataGridView, the code below shows how to copy the selected rows.

DataGridView1.EndEdit()
Dim TargetTable = DirectCast(bsData.DataSource, DataTable)
Dim rows = DataGridView1.SelectedRows
For Each row As DataGridViewRow In rows
    TargetTable.ImportRow(CType(bsData.Item(row.Index), DataRowView).Row)
Next

-------------------------------------------------------------------------------------------------------------------------
I tend to work from the DataTable (the DataSource) rather than the DataGridView. The above gives both approachs. You can modify the last one to exclude the BindingSource.
________________________________________
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


source "https://social.msdn.microsoft.com/Forums/vstudio/en-US/e1c01817-1adb-4053-a5df-814ccd93abdb/copy-datagridview-data-to-another-datagridview?forum=vbgeneral"

Saturday, 25 February 2017

VB.NET : Get MAC address

Imports System.Net.NetworkInformation


Dim macs() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
MsgBox(mac(1).GetPhysicalAddress.ToString)

Friday, 24 February 2017

VB.NET : Create folder if does not exist

'at top import below namespace

Imports System.IO

If Not Directory.Exists("D:\db") Then
        Directory.CreateDirectory("D:\db")
End If