# useGridSelection

Hook for programmatic selection control.

Must be used within a DataGrid component tree with the selection feature enabled.
Uses React context, so it works reliably regardless of when the grid mounts.

```ts
useGridSelection(selector: string): SelectionMethods<TRow>
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `selector` | <code>string</code> | Optional CSS selector to target a specific grid element via
  DOM query instead of using React context. Use when the component contains
  multiple grids, e.g. `'tbw-grid.primary'` or `'#my-grid'`. |

#### Example

```tsx
import { useGridSelection } from '@toolbox-web/grid-react/features/selection';

function ExportSelectedButton() {
  const { getSelection, clearSelection } = useGridSelection();

  const handleExport = () => {
    const selection = getSelection();
    if (!selection) return;
    // Derive rows from selection.ranges and grid.rows
    clearSelection();
  };

  return <button onClick={handleExport}>Export Selected</button>;
}
```
