0% found this document useful (0 votes)
58 views

Window Application

This document discusses different controls in .NET 2.0 window applications including tree view, list box, and grid view controls. It provides code examples for populating and manipulating data in each control type. For the tree view control, it demonstrates how to programmatically add nodes and subnodes to display an organizational hierarchy. For the list box control, it shows binding to a dataset, transferring items between list boxes, and removing selected items. For the grid view, it shows binding to a dataset and retrieving selected row values.

Uploaded by

api-26344848
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Window Application

This document discusses different controls in .NET 2.0 window applications including tree view, list box, and grid view controls. It provides code examples for populating and manipulating data in each control type. For the tree view control, it demonstrates how to programmatically add nodes and subnodes to display an organizational hierarchy. For the list box control, it shows binding to a dataset, transferring items between list boxes, and removing selected items. For the grid view, it shows binding to a dataset and retrieving selected row values.

Uploaded by

api-26344848
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Window Application in .NET 2.

0
1. Tree View Control:
treeViewOrganization.Nodes.Add("Bench Mark");
treeViewOrganization.Nodes[0].Nodes.Add("Branch...1");
treeViewOrganization.Nodes[0].Nodes[0].Nodes.Add("Department..1.1");
treeViewOrganization.Nodes[0].Nodes[0].Nodes[0].Nodes.Add("Roles..1.1.1");
treeViewOrganization.Nodes[0].Nodes[0].Nodes[0].Nodes.Add("Roles..1.1.2");

treeViewOrganization.Nodes[0].Nodes.Add("Branch...2");
treeViewOrganization.Nodes[0].Nodes[1].Nodes.Add("Department..2.1");
treeViewOrganization.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Roles..2.1.1");
treeViewOrganization.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Roles..2.1.2");

treeViewOrganization.ExpandAll();

TreeNode OrganizationNode = new TreeNode();


OrganizationNode.Name = row["OrganizationId"].ToString();
OrganizationNode.Text = row["OrganizationName"].ToString();
treeviewAllOrganization.Nodes.Add(OrganizationNode);

TreeNode BranchNode = new TreeNode();


BranchNode.Name = row["BranchId"].ToString();
BranchNode.Text = row["BranchName"].ToString();
OrganizationNode.Nodes.Add(BranchNode);

TreeNode DepartmentNode = new TreeNode();


DepartmentNode.Name = row["DepartmentId"].ToString();
DepartmentNode.Text = row["DepartmentName"].ToString();
BranchNode.Nodes.Add(DepartmentNode);

TreeNode RoleNode = new TreeNode();


RoleNode.Name = row["RoleId"].ToString();
RoleNode.Text = row["RoleName"].ToString();
DepartmentNode.Nodes.Add(RoleNode);

2. ListBox Control
2.1 Binding Data to the List Box using Dataset.

List Box name: lstBoxOrganization


DataSet Name: orgds

BLayer.Organization org = new BLayer.Organization();


DataSet orgds = new DataSet();
orgds = org.GetAllOrganizationDetails();
lstBoxOrganization.DisplayMember = "OrganizationName";
lstBoxOrganization.ValueMember = "organizationId";
lstBoxOrganization.DataSource = orgds.Tables[0];
2.2. Add Selected Items from one List Box Control to another.

foreach (DataRowView row in lstAllBoxOrganization.SelectedItems)


{
lstBoxOrganizationAdd.DisplayMember =row["OrganizationName"].ToString();
lstBoxOrganizationAdd.ValueMember = row["OrganizationId"].ToString();;
lstBoxOrganizationAdd.Items.Add(row);

2.3 Remove an Item from the ListBox Control.

foreach (object obj in lstBoxOrganizationAdd.SelectedItems)


{
lstBoxOrganizationAdd.Items.Remove(obj);
if(lstBoxOrganizationAdd.SelectedItems.Count == 0)
{
return;
}

3. GridView Control
3. 1 Binding Data to the Grid View using Dataset

Department dept = new Department();


DataSet deptds = new DataSet();
deptds = dept.GetAllDeparment();
dgrdviewDepartment.DataSource = deptds.Tables[0];

3.2. How to get selected rows from the Grid View Control

ArrayList selectedDepartmentid = new ArrayList();

foreach (DataGridViewRow row in dgrdviewDepartment.Rows)


{

// Check box Value

bool selectrow = Convert.ToBoolean(row.Cells[0].Value);


if (selectrow == true)
{
selectedDepartmentid.Add(row.Cells[1].Value.ToString());
}
}

You might also like