ここでは、チェックボックスの列をRadioButtonとして機能させる方法を説明します。あなたの写真から、RadioBUttonsとしてすべての列を持つ1つの行が必要です->これはより複雑で、データをdatagridviewにバインドする方法に依存します。私はVB.NETでより多くの作業をしているので、ここにいくつかの構文エラーがあるかもしれません...
datagridviewにDataGridViewCheckBoxColumn列を作成するDataGridViewの3つのイベントを使用して、チェックボックス列がラジオボタンとして機能します
private Boolean bRbtnCurrentValue
private Int32 iColumnRadioBtn = 4
private Datagridview dgv //Only for this exapmle
//In Event dgv_CellBeginEdit
{
//Here we stored current value to variable
if (this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn)
this.bRbtnCurrentValue = this.dgv
}
//In Event dgv_CellEndEdit
{
//Here we update if value changed
Boolean bNewValue = this.dgv.CurrentCell.Value
if (this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn)
{
if(bNewValue=False)
this.dgv.CurrentCell.Value=this.bRbtnCurrentValue
else
//Here jo actions when value changed(database update etc.)
}
}
//Event dgv_ CurrentCellDirtyStateChanged
{
if(this.dgv.CurrentCell.ColumnIndex = this.iColumnRadioBtn) andalso (dgv.IsCurrentCellDirty = True)
{
foreach(DataGridViewRow dgvr In dgv.Rows)
{
If (dgvr.Index = dgv.CurrentRow.Index)
If (dgv.CurrentCell.Value = True)
dgv.CancelEdit() //True to False cannot be changed
else
If (dgvr.Cells(dgv.CurrentCell.ColumnIndex).Value=True)
dgvr.Cells(dgv.CurrentCell.ColumnIndex).Value = False
}
}
}