Populate ViewSheet data in datagrid

I am trying to get Sheet Names, Number & Revision in DataGrid tried various sample code tried even ChatGPT but no solution. I am able to retrieve data but unable to show it in DataGrid.

Tried creating basic one column and adding Sheet Names in DataGrid still not working

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FilteredElementCollector, ViewSheet

clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, DataGridView, DataGridViewAutoSizeColumnsMode
from System.Drawing import Size, Point

doc = _revit_.ActiveUIDocument.Document

# Get all sheets in the project
sheets = FilteredElementCollector(doc).OfClass(ViewSheet).ToElements()
sheet_names = [sheet.Name for sheet in sheets]

class SheetNameForm(Form):
        def _init_(self):
                self.Text = 'Revit Sheet Names'
                self.Size = Size(400, 500)
        
                self.dataGridView = DataGridView()
                self.dataGridView.Location = Point(10, 10)
                self.dataGridView.Size = Size(380, 450)
                self.dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
                
                self.dataGridView.DataSource = sheet_names
                self.dataGridView.Columns[0].Name = "Sheet Names"
                
                self.Controls.Add(self.dataGridView)

# Create and show the form
form = SheetNameForm()
Application.Run(form)

Hi @J.Sharma,
Does this code throws an error or it just shows an empty datagrid?

Youre passing a python list of strings as datasource, i don’t believe this is supported.

Look at this examples to understand how DataGridView works

https://www.dotnetperls.com/datagridview

Hi @sanzoghenzo you are right it shows empty DataGrid.

This was one of the codes generated by ChatGPT