Windows Datagrid - Add Radiobutton Column

K

Kevin Humphreys

Hi,
Is is possible to to add a new column to an Windows app unbound datagrid
where I can place a radiobutton control?
What I am trying to do is to have a radio button for each row on the
datagrid and have one of the radio button to be checked to treat this row as
the primary row ot the recordset.

VB.NET Code preferrably.

Thanks In Advance,
Kevin.
 
D

Daniel E. Ulfe

Assuming you are using a DataGridView... you will have to create your own
DataGridViewColumn...

Or you can use DataGridViewCheckBoxCell and write code inside the event
CellContentClick

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick

Dim lRow As DataGridViewRow

If e.ColumnIndex = 1 Then
lRow = DataGridView1.Rows(e.RowIndex)
If CType(lRow.Cells("Column2").Value, Boolean) = False Then
For Each lRow In DataGridView1.Rows
If lRow.Index <> e.RowIndex Then
lRow.Cells("Column2").Value = False
End If
Next
End If
End If
End Sub

In that way you can make sure there is only one checkbox "checked" at the
same time... well... that is the simplest way I can think of...

Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top