Мы вложили в подкласс элемент управления DataGridView и добавили это. Нам не нужна была функция перетаскивания - нам просто нужно было сообщить пользователю, когда по его запросу не было возвращено никаких данных.
У нас есть свойство emptyText, объявленное так:
private string cvstrEmptyText = "";
[Category("Custom")]
[Description("Displays a message in the DataGridView when no records are displayed in it.")]
[DefaultValue(typeof(string), "")]
public string EmptyText
{
get
{
return this.cvstrEmptyText;
}
set
{
this.cvstrEmptyText = value;
}
}
и перегружена функция PaintBackground:
protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
{
RectangleF ef;
base.PaintBackground(graphics, clipBounds, gridBounds);
if ((this.Enabled && (this.RowCount == 0)) && (this.EmptyText.Length > 0))
{
string emptyText = this.EmptyText;
ef = new RectangleF(4f, (float)(this.ColumnHeadersHeight + 4), (float)(this.Width - 8), (float)((this.Height - this.ColumnHeadersHeight) - 8));
graphics.DrawString(emptyText, this.Font, Brushes.LightGray, ef);
}
}