Различный ответ на мой более ранний, на основе воздействия Google Java Collections :
public static class Lists
{
public static List Of(T item)
{
return new List { item };
}
}
Тогда:
List x = Lists.Of("Hello");
я советую проверять GJC - он имеет много интересного материала в. (Лично я проигнорировал бы "альфа-" тег - это - только версия с открытым исходным кодом, которая является "альфой", и это основано на очень стабильном и в большой степени использовало внутренний API.)
Попробуйте обработать событие DataGridView.CellPainting .
Я решил аналогичную проблему, создав пользовательский тип ячеек и сжав элемент управления редактированием, как описал Брайан. Это не так уж сложно, и это единственный способ, который я знаю, чтобы не допустить рисования поверх всего при редактировании.
Что-то вроде этого должно сработать для вас:
public class PaintAccommodatingTextBoxCell : DataGridViewTextBoxCell
{
// Adjust the editing panel, so that custom painting isn't
// drawn over when cells go into edit mode.
public override Rectangle PositionEditingPanel(Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
// First, let base class do its adjustments
Rectangle controlBounds = base.PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
// Shrink the bounds here...
return controlBounds;
}
}
public class PaintAccommodatingTextBoxColumn : DataGridViewTextBoxColumn
{
PaintAccommodatingTextBoxCell templateCell;
public PaintAccommodatingTextBoxColumn()
{
templateCell = new PaintAccommodatingTextBoxCell();
}
public override DataGridViewCell CellTemplate
{
get
{
return templateCell;
}
set
{
PaintAccommodatingTextBoxCell newTemplate = value as PaintAccommodatingTextBoxCell;
if (newTemplate == null)
throw new ArgumentException("Template must be a PaintAccommodatingTextBoxCell");
else
templateCell = newTemplate;
}
}
}