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 }); }
Sometimes we need to transfer all the rows and columns of a DataGridView from one form to another. In this article I will transfer all the binded data of first form's grid view and bind them to second form's grid view.
Create two forms with dataGridView in each and a button on first form. Create a class to which your datagridview will bind like i create a student class having Name, Age and address field.
Bind the first form's gridview in C# language as
In the click event of button write the following code in C# language
And your second form's constructor have to look like the below code in C# language
So we have passed all the rows and columns of first form's gridview to second form's gridview.
Create two forms with dataGridView in each and a button on first form. Create a class to which your datagridview will bind like i create a student class having Name, Age and address field.
Bind the first form's gridview in C# language as
studList.Add(new Student() { Name = "Jacob", Age = 23, Address = "London" });
studList.Add(new Student() { Name = "Jaklin", Age = 25, Address = "US" });
studList.Add(new Student() { Name = "Julia", Age = 26, Address = "UK" });
dataGridView1.DataSource = studList;
studList.Add(new Student() { Name = "Jaklin", Age = 25, Address = "US" });
studList.Add(new Student() { Name = "Julia", Age = 26, Address = "UK" });
dataGridView1.DataSource = studList;
In the click event of button write the following code in C# language
List<Student> tempList = dataGridView1.DataSource as List<Student>;
new Form1(tempList).ShowDialog();
new Form1(tempList).ShowDialog();
And your second form's constructor have to look like the below code in C# language
public Form1(List<Student> sourceList)
{
InitializeComponent();
dataGridView1.DataSource = sourceList;
}
When we run this project and click on transfer button then both the form have same list of data e.g.
{
InitializeComponent();
dataGridView1.DataSource = sourceList;
}
Comments
Post a Comment