私が表示されるまで、実際の無効化]チェックボックスを取得するには、このようなことをやってしまった:
using System.Windows.Forms.VisualStyles;
public partial class YourForm : Form
{
private static readonly VisualStyleRenderer DisabledCheckBoxRenderer;
static YourForm()
{
DisabledCheckBoxRenderer = new VisualStyleRenderer(VisualStyleElement.Button.CheckBox.UncheckedDisabled);
}
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (e.RowIndex > -1)
{
int checkBoxColumnIndex = this.yourCheckBoxColumn.Index;
var checkCell = (DataGridViewCheckBoxCell)this.dataGridView[checkBoxColumnIndex, e.RowIndex];
var bounds = this.dataGridView.GetCellDisplayRectangle(checkBoxColumnIndex , e.RowIndex, false);
// i was drawing a disabled checkbox if i had set the cell to read only
if (checkCell.ReadOnly)
{
const int CheckBoxWidth = 16;
const int CheckBoxHeight = 16;
// not taking into consideration any cell style paddings
bounds.X += (bounds.Width - CheckBoxWidth)/2;
bounds.Y += (bounds.Height - CheckBoxHeight)/2;
bounds.Width = CheckBoxWidth;
bounds.Height = CheckBoxHeight;
if (VisualStyleRenderer.IsSupported)
{
// the typical way the checkbox will be drawn
DisabledCheckBoxRenderer.DrawBackground(e.Graphics, bounds);
}
else
{
// this method is only drawn if the visual styles of the application
// are turned off (this is for full support)
ControlPaint.DrawCheckBox(e.Graphics, bounds, ButtonState.Inactive);
}
}
}
}
}
私はそれぞれの行のセルを無効にしたい、私は、CellのEnabledプロパティを見つけることができませんでした。私はRowPostPaintイベントを使用しています。 –
それはwinformsですか? –
個々のセルを無効にする機能はないかもしれませんが、無効にするセルの値を元に戻すなど、セルがクリックされている間何かを行うことができます – Nick