Friday, October 22, 2010

Retrieving network computer names c#

Recently someone told me, he couldn't get the name of the computers on the network! so I tried to create and used some .net libraries but i couldn't get the name of the computer either. 
I'm only getting the I.P. address of computers on the certain network, so I look for some articles that could help me out! and found this micorosft's documentation click here



As you can see I only have two computers here! it works out for me! I hope this sample helps someone out !!!!

Tuesday, October 19, 2010

DataBinding Part 2(Navigation with Data Binding)

please refer to the first part of this sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataBinding
{
    public partial class Form2 : Form
    {

        private DataTable dt = null;
        private BindingManagerBase storeBinding;

        public Form2()
        {
            InitializeComponent();

            this.dt = clsInstance.Products.getProducts();

            this.txtProductID.DataBindings.Add("Text" , dt, "ProductID");
            this.txtProductName.DataBindings.Add("Text", dt, "ProductName");
            this.txtProductPrice.DataBindings.Add("Text", dt, "ProductPrice");

            this.storeBinding = this.BindingContext[dt];
            
            this.storeBinding.PositionChanged += new EventHandler(storeBinding_PositionChanged);
        }

        private void storeBinding_PositionChanged(object sender, EventArgs e)
        {
            int intRow = 1 + storeBinding.Position;

            this.lblCurrentRow.Text = string.Format("{0} of {1}", intRow, storeBinding.Count);

        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            if (storeBinding.Position > 0)
                storeBinding.Position -= 1;
            else
                storeBinding.Position = storeBinding.Count-1; 
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (storeBinding.Position != storeBinding.Count - 1)
                storeBinding.Position += 1;
            else
                storeBinding.Position = 0;
        }
    }
}

Monday, October 18, 2010

DataBinding Part 1

Binding to a list control is one of the most common task. I think most of the .NET list controls has a DataSource property in which accepts reference to any datasource(IList).
In our example I used MSACCESS for our backend database for simplicity.
This will be our example data for the rest of the databinding samples!








Sample screenshot of the application!











Saturday, October 16, 2010

Inputbox C#

Many vb/vb.net developers are used with the InpuBox(it displays a prompt and waits for the user to input text then returns a string containing the contents of the text box)..... 
In using C# InputBox is not available!!!! so i decided to create one. 
So i might help someone who needs this kind of functionality!


Monday, October 4, 2010

Get Running Process C#

If you want to access local computer process this might get you started! In this example i used a windows form with a  listview and imagelist. Nothing fancy just a simple application that might help you started with System.Diagnostics.Process check Microsoft's documentation click here

Saturday, October 2, 2010

Sample Login C#

Another sample from me! Just a basic and simple one! I hope someone may benefit from this one! So if you are interested .......

Terminate a process using C#

Sometimes in our application we need to terminate a process or a service.
In our example i'll be terminating a notepad. However, in some books that I have read
for windows-based applications,call Process.CloseMainWindow to send close message to the applications main window.If ever the windows-based application ignored Process.CloseMainWindow, or non-windows application, call the Process.Kill method.
Sample output

Detect network card or adapter, changes in C#

In this example, we are going to check the Sysetm.Net.NetworkInformation.NetworkChange Class to have the mechanism to check whether changes to network occurs during the life of your application. Occurding to microsoft's documentation add handlers to NetworkAddressChanged and NetworkAvailabilityChanges events.
Sample output