> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/gum-tool-code-contributing-and-plugins/datauigrid/reflection.md).

# Reflection

The default behavior for DataUiGrid is to reflect properties from the assigned Instance. When the Instance is assigned, the Grid automatically populates its Categories with members based on reflection.

```csharp
// Initialize
// Initially categories will be empty
grid.Instance = someObject;
// Now, the Categories contains one instance, 
// and this category contains one InstanceMember for each reflected property
```

Properties which have the `System.ComponentModel.CategoryAttribute` are categorized according to the category assigned. Otherwise, properties are put in the Uncategorized category.

## Manually Selecting Properties

By default all public fields and properties are displayed in a DataUiGrid. To control which properties are shown, the categories can be cleared, and individual InstanceMembers can be added for the desired properties.

For example, the following code clears the properties, and shows only X, Y, and Z:

```csharp
// Initialize
grid.Instance = viewModel;

var category = grid.Categories[0];

category.Members.Clear();

category.Members.Add(new InstanceMember("X", viewModel));
category.Members.Add(new InstanceMember("Y", viewModel));
category.Members.Add(new InstanceMember("Z", viewModel));

```

## Customizing InstanceMembers

Reflection-based InstanceMembers can be customized by changing their properties. For example, the following can be used to display a Name property which is read-only:

```csharp
var nameMember = category.Members.First(item => item.Name == "Name");
nameMember.IsReadOnly = true;
```

Individual getters and setters can be modified. For example, to add validation to an assignment, the setter can be modified as shown in the following code:

```csharp
nameMember.CustomSetPropertyEvent += (assignedInstance, args) =>
{
    var asMyType = (MyType)assignedInstance;
    var newName = (string)args.Value;
    if (DoesNameAlreadyExist(newName))
    {
        // Show some form of validation like a popup
        
        // by marking this as cancelled, the view dispaying the property
        // will not perform additional processing of the assignment:
        args.IsAssignmentCancelled = true;
    }
    else
    {
        asMyType.Name = newName;
    }
};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/gum-tool-code-contributing-and-plugins/datauigrid/reflection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
