Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Needed...ComboBox #57

Open
kannanrs opened this issue Mar 26, 2024 · 6 comments
Open

Help Needed...ComboBox #57

kannanrs opened this issue Mar 26, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@kannanrs
Copy link

Hi..

How to add items to Combobox in Codebehind..

TIA

@ziomek64
Copy link
Contributor

ziomek64 commented Mar 26, 2024

Bind items or items source I think in combobox to some collection in your code. Add items to this collection. Haven't used it but something like that perhaps. You have list of properties in docs https://mdc-maui.github.io/combo-box.

If you by any chance don't know what binding is learn that first and how mvvm works

@kannanrs
Copy link
Author

Will update soon

@Chupakabra0
Copy link

Chupakabra0 commented Mar 30, 2024

Bind items or items source

Seems to be binding for ComboBox properties like Items and ItemsSource doesn't work at least at the actual preview version. I've tried to bind it with List<string>, ObservableCollection<string>. I've even tried to bind it with List<Material.Components.Maui.MenuItem>, used converters, etc. Nothing helped.

Tried to do it by editing the sample project from develop brunch. Same sad result, but sample project from master worked perfectly (but somehow it breaks Android build so still sad).

@yiszza
Copy link
Collaborator

yiszza commented Mar 31, 2024

Copy!

@yiszza yiszza added the bug Something isn't working label Mar 31, 2024
@kannanrs
Copy link
Author

kannanrs commented Apr 2, 2024

Bind items or items source

Seems to be binding for ComboBox properties like Items and ItemsSource doesn't work at least at the actual preview version. I've tried to bind it with List<string>, ObservableCollection<string>. I've even tried to bind it with List<Material.Components.Maui.MenuItem>, used converters, etc. Nothing helped.

Tried to do it by editing the sample project from develop brunch. Same sad result, but sample project from master worked perfectly (but somehow it breaks Android build so still sad).

yes.. did all that.. and still couldnt... can wait... why not...

@sthakkar0687
Copy link

I am able to add items to combobox from code behind file. But You will Have to Make Observable Collection of Material.Components.Maui.MenuItem. And you will have to Add to the Items Property in combobox.

For eg there are 2 ways :
1 ) Way to add single Item through foreach loop:

foreach(var item in myCollection)
{
combobox1.Items.Add(new Material.Components.Maui.MenuItem { Text = item.PropertyName });
}

  1. Way to add collection of Items by making Observable Collection.

Use Linq.

var cmbItemsCollection = new ObservableCollection<Material.Components.Maui.MenuItem>(mycollection.Select(p=> new Material.Components.Maui.MenuItem() { Text = p.PropertyName }).ToList());

//Now add the observable collection in the Combobox items :

combobox1.Items.AddRange<Material.Components.Maui.MenuItem>(cmbItemsCollection);

Adding items is done , but When there are many items, there is no scrollbar coming.
If anybody finds a way to do that, Please share.

Thank you,
Sagar Thakkar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants