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 }); }
Dropdown list provides user to select an item from the existing list of items. Combo Box is a control allowing the user to either to type a value into the control or choose from a list. It means it is a combination of textbox and a drop down list.
Combo Box can contain a collection of objects of any type, it means it is an Items Control. To add some items in combo Box through XAML:
The above code snippet is used to simply add string type data to combo box. By using the above code snippet a combo box with three items will be created like in following image:
The same combo box can also be added dynamically using the following code snippet of c# language.
Whenever you change the selected item of this combo box, it will show a message as written in above code.
Combo Box can contain a collection of objects of any type, it means it is an Items Control. To add some items in combo Box through XAML:
<ComboBox Name="cmbBox">
<ComboBox.Items>
<sys:String>First Item</sys:String>
<sys:String>Second Item</sys:String>
<sys:String>Third Item</sys:String>
</ComboBox.Items>
</ComboBox>
<ComboBox.Items>
<sys:String>First Item</sys:String>
<sys:String>Second Item</sys:String>
<sys:String>Third Item</sys:String>
</ComboBox.Items>
</ComboBox>
The above code snippet is used to simply add string type data to combo box. By using the above code snippet a combo box with three items will be created like in following image:
The same combo box can also be added dynamically using the following code snippet of c# language.
ComboBox cmbBox = new ComboBox();
cmbBox.Name = "cmbBox";
cmbBox.Items.Add("First Item");
cmbBox.Items.Add("Second Item");
cmbBox.Items.Add("Third Item");
Now add this combo box to the container to which you want. The same combo box as in above image will be generated using this code snippet. We can perform any other operation on the click event of selection changed event of combo box. Generate the selectionChanged event and write it as the following code snippet.cmbBox.Name = "cmbBox";
cmbBox.Items.Add("First Item");
cmbBox.Items.Add("Second Item");
cmbBox.Items.Add("Third Item");
private void cmbBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("ComboBox Selection Changed");
}
{
MessageBox.Show("ComboBox Selection Changed");
}
Whenever you change the selected item of this combo box, it will show a message as written in above code.
Comments
Post a Comment