Dynamic Add Data into TreeView in C#

This technique apply for nested data store on relational dbms, for examples:

|  ID     |  Name  | ParentID |
|  1     |  A     | 0        |
|  2     |  B     | 0        |
|  3     |  C     | 0        |
|  4     |  a     | 1        |
|  5     |  b     | 1        |
|  6     |  c     | 2        |
|  7     |  d     | 3        |
|  8     |  e     | 3        |

And we want to show in Treeview control as:


So we do not need to use [Loop] to insert sub tree in to other tree.

IEnumerable<Table1> dataCollection =  // From table [Table1] “in Linq code”;

foreach(var record in dataCollection)
if(record.ParentID == 0)
TreeviewControl.Nodes.Add(record.ID.toString(), record.Name);
TreeNode[] tn = TreeviewControl.Nodes.Find(record.ParentID.toString(), true);
tn[0].Nodes.Add(record.ID.toString(), record.Name);

How to call a .NET web service from android?

Hai, Finally i got the solution for my own question.

Here is the code:

package projects.ksoap2sample;

import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.app.; import android.os.; import android.widget.TextView;

public class ksoap2sample extends Activity { /** Called when the activity is first created. */ private static final String SOAP_ACTION = “http://tempuri.org/HelloWorld&#8221;;

private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = ""; TextView tv; @Override public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     tv=(TextView)findViewById(R.id.text1);     call(); } public void call() {         try {         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);         request.addProperty("passonString", "Rajapandian");         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);         envelope.dotNet=true;         envelope.setOutputSoapObject(request);         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);         androidHttpTransport.call(SOAP_ACTION, envelope);         Object result = (Object)envelope.getResponse();         tv.setText(result.toString());     } catch (Exception e) {         tv.setText(e.getMessage());         } } 


Regards Rajapandian

Referenced by: http://stackoverflow.com/questions/1048310/how-to-call-a-net-web-service-from-android

Connecting to .NET web service from Android

If you are having trouble using .NET Web Services with the Android Platform, you have probably reached to the solution here.

I am here demonstrating the steps using which you can consume data from the .NET web service in your android app. In order to use .Net web Service from your android application you need to first download the ksoap2 android API. Follow the link to download ksoap2 API for android.

After downloading the API, extract the zip file to the file system. Open your Android Project and navigate to the Project Properties. In the project properties go to Java Build Path and say Add External JARs.

Add the reference to the extracted ksoap2-j2se-full-2.1.2.jar file from the downloaded API. You are now ready to use ksoap2 to connect to the .NET web service via Android.

Let’s assume a .NET web service with two methods “Hello World” that returns a string and “Add” that accepts two numbers and returns their sum. Following is the WSDL file of the web service.

From the above WSDL file we get the following Information about the web service:

In order to use this Web Service with our android app:

  1. Open the java file from where you would like to access the Web Service
  2. Include the class library for ksoap2

    import org.ksoap2.*;
    import org.ksoap2.serialization.*;
    import org.ksoap2.transport.*;
    import org.w3c.dom.Text;

  3. Define Web Service Properties in the class

    private static final String NAMESPACE = “http://localhost/TestWebService/&#8221; ;
    private static final String URL = ” http://TestServer/Test/service.asmx&#8221;;
    private static final String HelloWorld_SOAP_ACTION = “http://localhost/TestWebService/HelloWorld&#8221;;
    private static final String METHOD_NAME1 = “HelloWorld”;
    private static final String Add_SOAP_ACTION = “http://localhost/TestWebService/Add&#8221;;
    private static final String METHOD_NAME2 = “Add”;

  4. Add methods to call the web service methods and retrieve the results

    public void GetHelloWorld() {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
    SoapSerializationEnvelope envelope =
    new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    androidHttpTransport.call(HelloWorld_SOAP_ACTION, envelope);
    java.lang.String receivedString = (String)envelope.getResponse();

    catch(Exception e)

    public void GetAdd() {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME2);

    PropertyInfo num1 = new PropertyInfo();

    PropertyInfo num2 = new PropertyInfo();

    SoapSerializationEnvelope envelope =
    new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    androidHttpTransport.call(Add_SOAP_ACTION, envelope);
    java.lang.Integer receivedInt = (Integer)envelope.getResponse();

    catch(Exception e)


  5. If you app require access to an array, you can use the following code:

    ArrayList<String> a = new ArrayList<String>();
    androidHttpTransport.call(SOAP_ACTION, envelope);
    java.util.Vector<Object> receivedStrings = (java.util.Vector<Object>)envelope.getResponse();
    if(receivedStrings != null)
    for(Object curStrings : receivedStrings)
    catch(Exception e)

Referenced by: http://composedcrap.blogspot.com/2009/08/connecting-to-net-web-service-from.html

Treeview Control – chek child if parent is checked for C#

private void TreeView1_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
	// For Select all to sub tree
	TreeNode parent_node = e.Node;
	bool is_checked = parent_node.Checked;
	for (int i = 0; i <= e.Node.Nodes.Count - 1; i++) {
		SetSubtreeChecked(parent_node.Nodes(i), is_checked);
	bool blnUncheck = false;


	//Check to see if a parent node exists.

	if ((e.Node.Parent != null)) {
		//Loop through the child nodes.
		foreach (TreeNode child in e.Node.Parent.Nodes) {
			//Check to see if the current node is unchecked.
			if (child.Checked == true) {
				//Set the variable.
				blnUncheck = true;
		//Check the variable.
		if (blnUncheck == false) {
			//Check the parent node.
			e.Node.Parent.Checked = false;
		} else {
			//Uncheck the parent node.
			e.Node.Parent.Checked = true;
//'          For Tree view Items Validation
private void SetSubtreeChecked(TreeNode parent_node, bool is_checked)
	// Set the parent's Checked value.
	parent_node.Checked = is_checked;
	// Set the child nodes' Checked values.
	for (int i = 0; i <= parent_node.Nodes.Count - 1; i++) {
		SetSubtreeChecked(parent_node.Nodes(i), is_checked);

Referenced by: http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/f4269ae8-f788-4637-a454-df0f6bf05db5/

How can I validate input to the edit control of a cell in a DataGridView?

<code>private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
//Remove any KeyPress events already attached
e.Control.KeyPress -= new KeyPressEventHandler(FirstEditingControl_KeyPress);
e.Control.KeyPress -= new KeyPressEventHandler(SecondEditingControl_KeyPress);

//Choose event to wire based on control type
if (e.Control is NumericTextBox)
e.Control.KeyPress += new KeyPressEventHandler(FirstEditingControl_KeyPress);
} else if (e.Control is CurrencyTextBox)
e.Control.KeyPress += new KeyPressEventHandler(SecondEditingControl_KeyPress);

Referenced by: http://stackoverflow.com/questions/2651105/how-can-i-validate-input-to-the-edit-control-of-a-cell-in-a-datagridview

How to Install Android OS on PC

Mobile phones under the android platform always deserve a best place in market. So if you got messed with android OS and want to try it in your netbook or laptop here is the procedure to experiment it. You can install in your memory cards or flash drives to test android OS on your system.

Download android from Android-x86 and copy it in your flash drive or memory card. Scroll down and download it from the stable release section of the site. This will download an ISO file from the website. Also Make sure your memory device having memory more than 256MB and make your memory drive clean before copying android into it.

You also need UNetbootin (Universal Netboot Installer) to run android on your system. So download it from UNetbootin site. It is available for all the leading operating systems. So choose your OS to download UNetbootin from the site.

Now I have downloaded UNetbootin for my windows platform. All you need to do is insert your drive which you going to install your android OS. UNetbootin extracts the ISO file of android OS which you downloaded and install it in the target disk. The first step of your installation is shown in the screen shot below.

After selecting the target disk, android will start extracting from ISO file and installed in your disk. Now your flash drive will get installed with android OS. This may take few minutes depending on the speed of your flash drive.

Once you get done with the process you will asked to reboot your system. If you wish you can reboot system immediately or else you just exit and run android when you want. Now your system is ready to run android OS. All you need to do is reboot your system with the flash drive. Change the boot setup to boot from removable disk.

In default it will be available to boot from your hard drive. So press F2 on reboot of your system. Go to Boot menu in the BIOS setup and change the boot setup to boot from removable disc. Then press F10 to save your changes and exit from BIOS setup. Now your system will restart and boot from your removable disc. This will bring a menu infront of you with the following options.

Select Live CD- Run Android-x86 without installation. Then your android OS will start booting and you need to wait for few minutes until it gets loaded. After a couple of minutes you will straightly get into your personal desktop. The default applications will be available on the home screen and for more applications go to menu and select the applications you need.

By default android give access to webcam and Wi-Fi. So that after entering into the menu you can install the apps you need. You can carry your memory card or flash drive to anywhere and use your own android OS. But your apps installed will be gone when you reboot your system or when you put your removable device in another system. This provides a better interface for the persons who are all using the public systems.

Follow these steps, try installing android in your system. share your comments and doubts in the comment box below.

Referenced by: http://www.dailytut.com/mobile-phone/how-to-install-android-os-on-pc-laptop.html

Copy file to remote computer using remote admin credentials

Correct me if I’m wrong, but you can use LogonUser to impersonate a local group also not only domain accounts.
by: Shay Erlichmen

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security.Permissions;
public class Form1
	[DllImport("advapi32.DLL", SetLastError = true)]
	public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
	private void Button1_Click(System.Object sender, System.EventArgs e)
		IntPtr admin_token = default(IntPtr);
		WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
		WindowsIdentity wid_admin = null;
		WindowsImpersonationContext wic = null;
		try {
			MessageBox.Show("Copying file...");
			if (LogonUser("Local Admin name", "Local computer name", "pwd", 9, 0, ref admin_token) != 0) {
				wid_admin = new WindowsIdentity(admin_token);
				wic = wid_admin.Impersonate();
				System.IO.File.Copy("C:\\right.bmp", "\\\\\\testnew\\right.bmp", true);
				MessageBox.Show("Copy succeeded");
			} else {
				MessageBox.Show("Copy Failed");
		} catch (System.Exception se) {
			int ret = Marshal.GetLastWin32Error();
			MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString());
		} finally {
			if (wic != null) {

Referenced by: http://stackoverflow.com/questions/766033/copy-file-to-remote-computer-using-remote-admin-credentials