Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What is the substitute in WFP for System.Windows.Forms.DataGridView? Thanks.

What I have tried:

The substitute in WFP for System.Windows.Forms.DataGridView?
Posted

 
Share this answer
 
Comments
s yu 14-May-24 10:00am    
Richard: I read the article, but could not find a WPF control that can substitute the DataGridView. Could you provide additional hint? Thanks.
Richard Deeming 14-May-24 10:06am    
In what way does the DataGrid control not "substitute the DataGridView"?

If you want recommendations for a control with specific features, then you need to provide details of the features you're looking for.
Richard linked you to the DataGrid control. It's not the same as the DataGridView control in Windows forms. It's probably what you're looking for.

I asked MS Copilot for some sample code. The DataGrid control is not picky about where it gets its data from. The source could just as easily have been a database table/view or even an XML file.
C#
<Window x:Class="WpfTutorialSamples.DataGrid_control.SimpleDataGridSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SimpleDataGridSample" Height="180" Width="300">
    <Grid Margin="10">
        <DataGrid Name="dgSimple"></DataGrid>
    </Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Windows;

namespace WpfTutorialSamples.DataGrid_control
{
    public partial class SimpleDataGridSample : Window
    {
        public SimpleDataGridSample()
        {
            InitializeComponent();

            List<User> users = new List<User>();
            users.Add(new User() { Id = 1, Name = "John Doe", Birthday = new DateTime(1971, 7, 23) });
            users.Add(new User() { Id = 2, Name = "Jane Doe", Birthday = new DateTime(1974, 1, 17) });
            users.Add(new User() { Id = 3, Name = "Sammy Doe", Birthday = new DateTime(1991, 9, 2) });

            dgSimple.ItemsSource = users;
        }
    }

    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime Birthday { get; set; }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900