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 }); }
[Solved] Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion.
[Solved] Rows cannot be programmatically removed unless the DataGridView is data-bound to an IBindingList that supports change notification and allows deletion. When you bind the Datagridview with List in windows form. You get error when you delete row from it. According to article title, first to implement your List from IBindingList interface, if you want to solve this issue. Suppose, you want to bind your DataGridView with this class, which is mentioned below:
public partial class userAccount
{
public decimal Account_No { get; set; }
public string Name { get; set; }
}
}
Then you write simple code for this :
List<userAccount> ua= new List<userAccount>();
ua.Add(new userAccount(){Account_No=1000000008, Name ="Jacob"});
dataGridView1.DataSource = ua;
After binding the DataGridview, you will write the code for remove row from dataGridview.
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
After that you got error, which is mentioned below:
public partial class userAccount
{
public decimal Account_No { get; set; }
public string Name { get; set; }
}
}
Then you write simple code for this :
List<userAccount> ua= new List<userAccount>();
ua.Add(new userAccount(){Account_No=1000000008, Name ="Jacob"});
dataGridView1.DataSource = ua;
After binding the DataGridview, you will write the code for remove row from dataGridview.
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
After that you got error, which is mentioned below:
[Solution]
Bind DataGridView with IBindingList<userAccount> . Now the code is:
BindingList<userAccount> bi = new BindingList<userAccount> ();
bi.Add(new userAccount(){Account_No=1000000008, Name ="Jacob"});
dataGridView1.DataSource = bi;
dataGridView1.DataSource = bi;
After binding the DataGridview, you will write the code for remove row from dataGridview.
bi.RemoveAt(dataGridView1.SelectedRows[0].Index);
Comments
Post a Comment