PublicSubNew()
InitializeComponent()
Dim p As ICollectionView = Product.GetProducts(100)
_flex.ItemsSource = p
_flex.CellFactory = New MyCellFactory()
End Sub' カスタムセルファクトリを作成します
PublicClass MyCellFactory
Inherits CellFactory
Private originText AsString = String.Empty
PublicOverridesFunction CreateCellEditor(grid As C1FlexGrid, cellType As CellType, rng As CellRange) As FrameworkElement
Dim control = MyBase.CreateCellEditor(grid, cellType, rng)
Dim bdr = TryCast(control, Border)
Dim txt = TryCast(bdr.Child, TextBox)
originText = txt.Text
AddHandler txt.TextChanged, AddressOf txt_TextChanged
Return control
End FunctionPrivateSub txt_TextChanged(sender AsObject, e As TextChangedEventArgs)
Dim t = TryCast(sender, TextBox)
RemoveHandler t.TextChanged, AddressOf txt_TextChanged
t.Text = originText & Convert.ToString(t.Text)
t.SelectionStart = t.Text.Length
End SubEnd Class
コードのコピー
publicpartialclass MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
_flex.ItemsSource = Product.GetProducts(100);
_flex.CellFactory = new MyCellFactory();
}
}
// カスタムセルファクトリを作成します
publicclass MyCellFactory : CellFactory
{
string originText = string.Empty;
publicoverride FrameworkElement CreateCellEditor(C1FlexGrid grid, CellType cellType, CellRange rng)
{
var control = base.CreateCellEditor(grid, cellType, rng);
var bdr = control as Border;
var txt = bdr.Child as TextBox;
originText = txt.Text;
txt.TextChanged += txt_TextChanged;
return control;
}
void txt_TextChanged(object sender, TextChangedEventArgs e)
{
var t = (sender as TextBox);
t.TextChanged -= txt_TextChanged;
t.Text = originText + t.Text;
t.SelectionStart = t.Text.Length;
}
}