Bonjour,
Voici mon petit soucis. J'ai un programme dans lequel je remplis un DataGridView avec une liste d'objet (de classe Employee par exemple).
En faisant cette méthode je peux par la suite pour d'autres fonctionnalités récupérer le type de l'objet avec la propriété DataBoundItem de DataGridViewRow lorsque je sélectionne une ligne (pour ensuite faire une conversion tel que "if (dgvRow.DataBoundItem is Employee emp)").
Le soucis, c'est qu'en remplissant un DataGridView avec une liste on ne dispose pas des fonctionnalités de tri sur les colonnes.
Du coup, j'ai convertis ma liste d'object en DataTable qui est par la suite utilisé pour le DataGridView. Sauf que, en faisant cela je perd l'information du type de base de mon objet (Employee) quand je fais le DataBoundItem. Le type devient "System.Data.DataRowView".
Y-a-t-il un moyen de récupérer le type de base de l'objet avant qu'il ne devienne un DataRow ?
Solution testée et non concluante :
- Convertir le DataRow en Employee : trop complexe à mettre en place du fait que certains paramètres de ma classe sont uniquement en ReadOnly (peux pas changer cela).
Merci d'avance pour vos retours
Partager