>>921
覆うのは良くないなと思ってはいたけど継承でできたわ
public class DataGridViewEX : System.Windows.Forms.DataGridView
{
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{//列ヘッダでのMouseDownで勝手に先頭のCellが選択されないようにする。ResizeとSort可
bool b = this.CurrentCell == null && this.HitTest(e.Location.X, e.Location.Y).Type == System.Windows.Forms.DataGridViewHitTestType.ColumnHeader;
base.OnMouseDown(e);
if (b) this.CurrentCell = null;
}
}
または
public class DataGridViewEX : System.Windows.Forms.DataGridView
{
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{//列ヘッダでのMouseDownを全て無効にする
if (this.HitTest(e.Location.X, e.Location.Y).Type == System.Windows.Forms.DataGridViewHitTestType.ColumnHeader) return;
base.OnMouseDown(e);
}
}
下は>>930と同じような使い勝手になるはず。MouseEventArgsだからクリックボタンによる処理もメソッドの中に組み込める
勝手に先頭のCellが選択されるのはFocus()やSelect()実行しても起こるけど、まず使わないだろうしそのあとにDataGridView.CurrentCell = nullを入れてもいい
列のResizeでCell選択されるの前に悩んでいてFirstDisplayedCellとFocusまで調べていたけど見た目だけの問題だし面倒だから諦めていた
その質問のおかげで改めて調べる気になったから逆に感謝w
>>928
例えばDataGridViewの子コントロールとして用意して(datagridview.Controls.Add(panel))、BackColorをTransparentにするだけ。特別なことはいらなかったはず