Search This Blog

Monday, March 10, 2014

AppActivate Visual Basic

VB.NET Functions > AppActivate

Activates an application that is already running.

Example:
Start and activate notepad

AppActivate(Shell("C:\Windows\System32\notepad.exe", AppWinStyle.NormalFocus))




CurDir Visual Basic

VB.NET Functions > CurDir 

Returns the current path.

Example:


MessageBox.Show(CurDir())







Thursday, March 6, 2014

C# Random Color

C# > Color > Random

Random rnd = new Random();


Color randomColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));





Change DataGridView column to Hyperlink Runtime

C# > DataGridViewDataGridViewLinkCell

Example: Change DataGridView column to Hyperlink Runtime


foreach (DataGridViewRow r in dgv.Rows)
{
DataGridViewLinkCell lc = new DataGridViewLinkCell();
       lc.Value = r.Cells[1].Value;
       dgv[1, r.Index] = lc;
}


private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
              return;
if (dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewLinkCell)
       {
             string link = "http://www...";
             if(e.ColumnIndex == 1)
                System.Diagnostics.Process.Start(link  +                          dgv.Rows[e.RowIndex].Cells[4].Value as string);
       }

}




Read save data to Registry C# Example

C# > Win32 > RegistryKey 

RegistryKey represents a key-level node in the Windows registry

Example:
Save user name to registry

RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("MyProgram");
if (regKey == null)
  regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("MyProgram");
if (regKey.GetValue("User", "") == null)
{
  regKey.SetValue("User", txtUser.Text);
}
else
{
  if (txtUser.Text != regKey.GetValue("User", "").ToString())
  {
    regKey.SetValue("User", txtUser.Text);
  }
}

regKey.Close();




Wednesday, March 5, 2014

Multiple Filter DataGridView DataSource

C# > DataGridViewMultiple Filter

RowFilter gets or sets the expression used to filter.

Example:

Filter by code or description


string rowFilter = string.Format("[{0}] like '%{1}%'", "Code", txtSearch.Text);
rowFilter += string.Format(" OR [{0}] like '%{1}%'", "Description", txtSearch.Text);

(DataGridView1.DataSource as DataTable).DefaultView.RowFilter = rowFilter;





Handle click event in Button Column in DataGridView

C#DataGridViewDataGridViewButtonColumn

Add DataGridViewButtonColumn to your DataGridView.
To handle button click use CellClickEvent.

Example

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
  if (e.ColumnIndex == dataGridView1.Columns["Browse"].Index && e.RowIndex >= 0)
  {
               
  }
}