# TableCell 表格单元格

AntdUI 表格支持把单元格值设置为特殊对象，以显示文本、徽标、标签、图片、链接、按钮、开关、进度条等。复杂单元格通常配合 `AntdUI.AntItem(key,value)` 行数据使用。

## 常见单元格类型

- `CellText(text)`：带颜色、前后缀图标的文本。
- `CellBadge(state,text)`：徽标状态，适合“在线/离线/处理中”。
- `CellTag(text,type)`：标签，适合分类、状态标签。
- `CellLink(id,text)`：链接文字。
- `CellButton(id,text,type)`：按钮，继承 `CellLink`。
- `CellProgress(value)`：进度条，value 范围通常为 0 到 1。
- `CellSwitch(checked)`：开关。
- `CellCheckbox(text,checked)` / `CellRadio(text,checked)`：复选/单选单元格。
- `CellImage(image)`：图片或 SVG 图片。

## 文本、徽标、标签、进度

```aardio
var text = AntdUI.CellText("已完成");
text.Fore = 0xFF008000;

var badge = AntdUI.CellBadge(AntdUI.TState.Success,"在线");

var tag = AntdUI.CellTag("VIP",AntdUI.TTypeMini.Primary);

var progress = AntdUI.CellProgress(0.65);
progress.Shape = AntdUI.TShape.Round;
```

> .NET 的 `System.Drawing.Color` 在 aardio 中就是 `0xAARRGGBB` 数值，传给 .NET 颜色属性时会自动转换；不需要调用 `System.Drawing.Color.FromArgb(...)` 或额外包装。

## 链接与按钮单元格

同一单元格可放多个 `CellLink` / `CellButton`。非空 aardio 数组可按目标参数类型自动转换为 `CellLink[]`，通常不必手工创建 CLR 数组。

```aardio
var buttons = [
    AntdUI.CellButton("edit","编辑",AntdUI.TTypeMini.Primary),
    AntdUI.CellLink("delete","删除")
];

var row = [
    AntdUI.AntItem("name","张三"),
    AntdUI.AntItem("ops",buttons)
];
```

处理按钮点击：

```aardio
grid.CellButtonClick = function(sender,e){
    select(e.Btn.Id) {
        case "edit" {
            winform.msgbox("编辑第 " + e.RowIndex + " 行");
        }
        case "delete" {
            winform.msgbox("删除第 " + e.RowIndex + " 行");
        }
    }
}
```

## AntItem[] 行数据示例

```aardio
import dotNet.AntdUI;
import dotNet; // 本例仅用于 dotNet.createArrayList()

var row = [
    AntdUI.AntItem("name","李四"),
    AntdUI.AntItem("state",AntdUI.CellBadge(AntdUI.TState.Processing,"处理中")),
    AntdUI.AntItem("tag",AntdUI.CellTag("NEW",AntdUI.TTypeMini.Success)),
    AntdUI.AntItem("progress",AntdUI.CellProgress(0.3))
];

var rows = dotNet.createArrayList();
rows.Add(row);

grid.DataSource = rows;
```

## 常用属性与方法

### CellText

- `Text`：显示文本。
- `Fore` / `Back`：文字与背景颜色。
- `Font`：字体。
- `PrefixSvg` / `SuffixSvg`：前缀/后缀 SVG。
- `SetText(...)`、`SetFore(...)`、`SetBack(...)`、`SetPrefix(...)`、`SetSuffix(...)`。

### CellBadge

- `Text`：显示文本。
- `State`：状态，常用 `AntdUI.TState.Success/Processing/Error/Warn/Default`。
- `Fore` / `Fill`：文字与填充颜色。
- `SetState(...)`、`SetText(...)`。

### CellTag

- `Text`：标签文本。
- `Type`：类型，常用 `AntdUI.TTypeMini.Primary/Success/Error/Warn/Info/Default`。
- `Fore` / `Back`：文字与背景颜色。
- `BorderWidth`：边框宽度。

### CellLink / CellButton

- `Id`：业务标识，按钮点击事件里常用。
- `Text`：显示文本。
- `Enabled`：是否启用。
- `Tooltip`：提示文本。
- `CellButton.Type`：按钮类型。
- `CellButton.Ghost` / `Shape` / `IconSvg` / `Loading`：按钮外观与状态。
- 常用链式方法：`SetBorder()`、`SetGhost()`、`SetIcon(...)`、`SetType(...)`、`SetLoading(...)`。

### CellSwitch / CellCheckbox / CellRadio

- `Checked`：选中状态。
- `Enabled`：是否启用。
- `AutoCheck`：点击时是否自动切换。
- `Text` / `CheckedText` / `UnCheckedText`：显示文本。

## 常见坑

- `CellLink[]`、`CellImage[]`、`AntItem[]` 这类参数通常可直接传非空 aardio 数组，例如 `[AntdUI.AntItem("name","张三")]`。
- 空数组 `[]` 无法推断 .NET 元素类型；此时才需要 `dotNet.createArray(type,0)` 或指定泛型集合。
- 若已经创建 CLR 数组，在 aardio 中 `netObjArray[1]` 会映射到 CLR 第 0 项；只有直接调用 `.SetValue(value,0)` / `.GetValue(0)` 这类 .NET 方法时才使用 0-based 索引。
- 多按钮单元格应监听 `Table.CellButtonClick`，不要用 `CellClick` 判断鼠标位置。
- `CellButton` 继承 `CellLink`，所以 `CellButton` 可放进 `CellLink[]`。
- 对于简单文本数据，优先用 `DataTable`；只有需要复杂单元格时再使用 `AntItem[]` 或对象列表。
