> Brian,
>
[quoted text clipped - 78 lines]
> >
> > B.
No. Best in another module, depending on how its called.
Anyway, if it is a DataGridView (as opposed to a DataGrid) this code
will not work.For a DataGridView there are no column styles, and
instead there are Columns collections, but they cannot be disassociated
from the DatGridView. Even the constructor requires the DataGridView it
is associated with.
Instead, you could use the following: (I'm still messing with it, so
this isn't complete.)
Private Sub Create_Column_Common(ByVal Column As DataGridViewColumn,
ByVal Name As String, ByVal Header As String, ByVal Read_Only As
Boolean)
With Column
.Name = Name
.HeaderText = Header
.ReadOnly = Read_Only
.DataPropertyName = Name
End With
End Sub
Public Function Create_Column_TextBox(ByVal Name As String, ByVal
Header As String, Optional ByVal Read_Only As Boolean = False) As
DataGridViewTextBoxColumn
Create_Column_TextBox = New DataGridViewTextBoxColumn
Create_Column_Common(Create_Column_TextBox, Name, Header,
Read_Only)
End Function
Public Function Create_Column_Checkbox(ByVal Name As String, ByVal
Header As String, Optional ByVal Read_Only As Boolean = False) As
DataGridViewCheckBoxColumn
Create_Column_Checkbox = New DataGridViewCheckBoxColumn
Create_Column_Checkbox.FalseValue = "Yes"
Create_Column_Checkbox.TrueValue = "No"
Create_Column_Common(Create_Column_Checkbox, Name, Header,
Read_Only)
End Function
Then to actually add the columns:
' This must be before .Fill() to stop the DGV from generated its own
column list.
<datagridview>.AutoGenerateColumns = False
<datagridview>.Columns.AddRange _
( _
New DataGridViewColumn() _
{ _
Create_Column_TextBox("Text_Column", "text"), _
Create_Column_Checkbox("Checkbosx_Column", "yes/no", True) _
} _
)
HTH,
B.
Guy Thornton - 24 Jul 2006 02:30 GMT
I was able to get your code suggestion to work. However, it is not doing
what I was intending. Remember that I have a Questionnaire Object that holds
a collection of questions. Each question has an answer property. I am
displaying the questions in the datagridview as column1 and the question
answer as column 2. My problem is that I need column to to switch between
being a textbox column or a combobox column depending on the type of answer
the question requires.
The code segment posted adds 2 separate columns. One a textbox column, the
other a boolean column.
If you have any further suggestions I am still searching for an answer to
this problem.
> > Brian,
> >
[quoted text clipped - 136 lines]
> HTH,
> B.