Gérer combobox différente d'un grid
Fermé
yann458
Messages postés
456
Date d'inscription
dimanche 29 mai 2011
Statut
Membre
Dernière intervention
13 mars 2024
-
6 mars 2017 à 09:27
yann458 Messages postés 456 Date d'inscription dimanche 29 mai 2011 Statut Membre Dernière intervention 13 mars 2024 - 9 mars 2017 à 12:07
yann458 Messages postés 456 Date d'inscription dimanche 29 mai 2011 Statut Membre Dernière intervention 13 mars 2024 - 9 mars 2017 à 12:07
A voir également:
- Gérer combobox différente d'un grid
- Gerer les profils netflix - Guide
- Gerer foyer netflix - Guide
- Ecriture differente facebook - Guide
- Gerer les applications qui se lancent au demarrage - Guide
- Barre d'erreur différente pour chaque point excel ✓ - Forum Excel
6 réponses
Whismeril
Messages postés
19022
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
17 avril 2024
928
6 mars 2017 à 09:59
6 mars 2017 à 09:59
Bonjour
et si tu postais plutôt le code du xaml et la partie de code behind qui gère la combobox dans le fil?
Voir ici comment poster un code lisible.
et si tu postais plutôt le code du xaml et la partie de code behind qui gère la combobox dans le fil?
Voir ici comment poster un code lisible.
yann458
Messages postés
456
Date d'inscription
dimanche 29 mai 2011
Statut
Membre
Dernière intervention
13 mars 2024
Modifié par baladur13 le 6/03/2017 à 14:06
Modifié par baladur13 le 6/03/2017 à 14:06
Ca ne coute rien de compiler un projet.
MainWindow.xaml
mainwindow.xaml.cs
viewmodel.cs
MainWindow.xaml
<Window x:Class="WpfApplicationGrid.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplicationGrid" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <local:viewmodel/> </Window.DataContext> <Window.Resources> <!-- CollectionViewSourceで参照出来るようにしておいて --> <CollectionViewSource x:Key="ListSource" Source="{Binding Path=Employees.lalist}" /> <CollectionViewSource x:Key="ResultatSource" Source="{Binding resultat}" /> <!--<DataTemplate x:Key="EmpTemplate" DataType="{x:Type local:Employee}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding resultat}"></TextBlock> </StackPanel> </DataTemplate>--> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="32"></RowDefinition> </Grid.RowDefinitions> <Grid Grid.Row="0"> <DataGrid AutoGenerateColumns="False" Name="myGrid" Margin="10" ItemsSource="{Binding Employees}" SelectionChanged="myGrid_SelectionChanged"> <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" /> <DataGridComboBoxColumn x:Name="truccombo" Header = "Party" SelectedItemBinding = "{Binding Path=resultat}" DisplayMemberPath="Name" /> <DataGridTextColumn Header="RName" Binding="{Binding Assign,Mode=OneWay}" /> </DataGrid.Columns> </DataGrid> </Grid> <Grid Grid.Row="1"> <Button Content="Button" HorizontalAlignment="Left" Height="12" Margin="138,10,0,0" VerticalAlignment="Top" Width="91" Click="Button_Click"/> </Grid> </Grid> </Window>
mainwindow.xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplicationGrid { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void myGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { object o = e.AddedItems[0]; Employee ee = o as Employee; if (ee != null) { truccombo.ItemsSource = ee.lalist; } } } private void Button_Click(object sender, RoutedEventArgs e) { int i = 4; e = e; } } }
viewmodel.cs
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WpfApplicationGrid { public class Lttt { private string _name; public string Name { get { return _name; } set { _name = value; } } public Lttt(string s) { _name = s; } } public class Employee : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; ObservableCollection<Lttt> _lista; /* public static ObservableCollection<string> _Genders; public ObservableCollection<string> Genders { get { return _Genders; } set { _Genders = value; } }*/ private Lttt _resultat; public Lttt resultat { get { return _resultat; } set { _resultat = value; if (PropertyChanged != null) { PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Assign")); } } } public string Name { get; set; } public string Assign { get { string sd = ""; if (_resultat!=null) sd = _resultat.Name; return sd; } } public ObservableCollection<Lttt> lalist { get { return _lista; } } public Employee(string _sn, ObservableCollection<Lttt> maliste) { Name = _sn; //Gender = _sg; _resultat = null; _lista = maliste; } } public class viewmodel { //private Lttt _resultat; public static ObservableCollection<Employee> Employees { get; set; } public viewmodel() { ObservableCollection<Lttt> _lista,_listb; _lista = new ObservableCollection<Lttt>(); _lista.Add(new Lttt("1")); _lista.Add(new Lttt("2")); _lista.Add(new Lttt("3")); _listb = new ObservableCollection<Lttt>(); _listb.Add(new Lttt("4")); _listb.Add(new Lttt("5")); _listb.Add(new Lttt("6")); Employees = new ObservableCollection<Employee>() { new Employee("ABCgroup1",_lista), new Employee("CDEFgroup1",_lista), new Employee("UVDgroup2",_listb), new Employee("XYZgroup2",_listb), }; //myGrid.ItemsSource = Employees; //Gender.ItemsSource = Genders; } } }
EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI Merci d'y penser dans tes prochains messages. |
Whismeril
Messages postés
19022
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
17 avril 2024
928
6 mars 2017 à 11:14
6 mars 2017 à 11:14
Tout le monde n'est pas chaud à télécharger un zip provenant d'un membre qu'on ne connait pas plus que ça.
De plus n'ayant pas Visual Studio sous la main, si ça avait été simple j'aurais peut-être pu t'aider.
De plus n'ayant pas Visual Studio sous la main, si ça avait été simple j'aurais peut-être pu t'aider.
Whismeril
Messages postés
19022
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
17 avril 2024
928
6 mars 2017 à 20:39
6 mars 2017 à 20:39
Merci à Baladur d'avoir corrigé ta coloration syntaxique, c'ets plus lisible.
J'ai voulu télécharger ton projet, mais il faut rentrer son adresse mail.
Il y a des services gratuits ou cela n'est pas nécessaire.
cijoint.com, dropbox, free gros fichiers etc...
J'ai voulu télécharger ton projet, mais il faut rentrer son adresse mail.
Il y a des services gratuits ou cela n'est pas nécessaire.
cijoint.com, dropbox, free gros fichiers etc...
Whismeril
Messages postés
19022
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
17 avril 2024
928
6 mars 2017 à 21:41
6 mars 2017 à 21:41
yann458
Messages postés
456
Date d'inscription
dimanche 29 mai 2011
Statut
Membre
Dernière intervention
13 mars 2024
7 mars 2017 à 19:59
7 mars 2017 à 19:59
oui qu'ils restent afficher.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Whismeril
Messages postés
19022
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
17 avril 2024
928
9 mars 2017 à 12:03
9 mars 2017 à 12:03
Bonjour
un de mes collègues (bien plus calé que moi en WPF, mais trop timide pour répondre sur le forum) m'a dit que ce comportement est les comportement normal.
Le mieux selon lui est d'utiliser une listview, et de mettre une combobox en changeant le datacontext.
Un peu comme fait là
https://stackoverflow.com/questions/19565718/combobox-inside-listview-binding
un de mes collègues (bien plus calé que moi en WPF, mais trop timide pour répondre sur le forum) m'a dit que ce comportement est les comportement normal.
Le mieux selon lui est d'utiliser une listview, et de mettre une combobox en changeant le datacontext.
Un peu comme fait là
https://stackoverflow.com/questions/19565718/combobox-inside-listview-binding
yann458
Messages postés
456
Date d'inscription
dimanche 29 mai 2011
Statut
Membre
Dernière intervention
13 mars 2024
9 mars 2017 à 12:07
9 mars 2017 à 12:07
merci