Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

How to bind TabControl with database in windows forms

TabControl manages and displays a related collection of tabs that can contain controls and components. We can add multiple pages in a single form and each page can contain its individual set of controls that can displayed when that tab is selected.

When we add a TabControl in our form then it will add three Tab Pages as default pages and tabPage1 will be selected tab. We can remove any tabPage from that control or can add a new tabPage.

Create a tab page

To add a tab page we can use Add method of TabPages property. Following line of code will add three tab pages without any control

tabControl1.TabPages.Add("Page1");
tabControl1.TabPages.Add("Page2");
tabControl1.TabPages.Add("Page3");

Inserting a tabPage with a label control:

Label label = new Label();    //New labal control
label.Text = "This is the control which will added to TabPage";    //set text property of label

TabPage tabPage = new TabPage();    // create a new tabpage
tabPage.Text = "Tab Page 1";    // set text property of tabpage
tabPage.Controls.Add(label);    //add label control to above tabpage

tabControl1.TabPages.Add(tabPage);    //finally add tabpage to our tabcontrol

Remove a tab page 

To remove a tab page we can use Remove method of TabPages property. Using following line of code we can remove selected tab from our tabControl:

tabControl1.TabPages.Remove(tabControl1.SelectedTab);

Load tabpages from Database 

In the following example we will add tabPage according to our departments. Each tab contains a list of employees working in that department. For showing list of employees we used a DataGridView in a UserControl. When we add a tabPage then we will load userControl in that tabPage.

Step 1:
Create two tables i.e. Department and Employee (described in previous article) in our database.

Step 2:
Insert some records in both tables (described in previous article).

Step 3:
Add a UserControl to our project and then add a DataGridView that will contain list of employees. Write following code in constructor of UserControl:
  
public EmployeeUserControl(Department dept)
{
       InitializeComponent();
       DataContext dc = new DataContext();
       var employees = from temp in dc.Employee
                                where temp.Department.Name == dept.Name
                                select new
                                {
                                       temp.Name,
                                       temp.Email,
                                       temp.Mobile
                                 };
       empDataGridView.DataSource = employees.ToList();
 }
As in above code datagridview will bind to the list of employees according to department.

Step 4:
Now finally in our form’s constructor write below line of codes to add pages to tabControl
foreach (var item in dc.Department)
{
        TabPage newTab = new TabPage(item.Name);
         newTab.Controls.Add(new EmployeeUserControl(item));
         tabControl1.TabPages.Add(newTab);
}

Download Source

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of