Search This Blog

Thursday, March 6, 2014

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)
  {
               
  }
}





Call Statement VB.NET Example

VB.NET > Statements > Call


Call transfers control to a function or dynamic-link library.
Call keyword is used when the called expression doesn't start with an identifier.


Example:


Class mClass
    Public Sub Method()
        MessageBox.Show("Call statement")
    End Sub
End Class

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call New mClass().Method()
    End Sub

End Class





Tuesday, March 4, 2014

HttpResponse ASP.NET

ASP.NET > System.WebHttpResponse 

Encapsulates HTTP response information from an ASP.NET application.





ASP.NET System.Web

ASP.NET > System.Web

System.Web contains classes and interfaces that enable browser-server communication.





Rss Feed Reader Vb.net Example

VB.NET > XML > Rss Feed Reader






Example


 Dim url As String = "http://rss.cnn.com/rss/cnn_latest.rss"
        Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
        Dim response = rssFeed.GetResponse()
        Dim rssStream = response.GetResponseStream()

        Dim rssDoc As New XmlDocument()
        rssDoc.Load(rssStream)
        Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
        Dim i As Integer = 0
        Dim dt As DataTable = New DataTable("table")
        dt.Columns.Add("title", Type.GetType("System.String"))
        dt.Columns.Add("link", Type.GetType("System.String"))

        While i < rssItems.Count
            Dim node As XmlNode = rssItems.Item(i).SelectSingleNode("title")
            Dim title As String
            Dim link As String
            If node IsNot Nothing Then
                title = node.InnerText
            Else
                title = ""
            End If

            node = rssItems.Item(i).SelectSingleNode("link")
            If node IsNot Nothing Then
                link = node.InnerText
            Else
                link = ""
            End If
            Dim dr As DataRow = dt.NewRow()
            dr("title") = title
            dr("link") = link

            dt.Rows.Add(dr)

            i += 1
        End While

        DataGridView1.DataSource = dt