datagridview Combobox column

S

Simon Whale

Hi all,

[vb2008]

I need help with the following, I have a grid that i have put on there 2
textbox's and a combobox column which works ok.

When i then add the data by using the following code below, it works, my
problem is with the combobox "YesNo" it put the complete contents of the
datatable into the combobox for each row. My question is how can i limit
the drop down to 1 yes and 1 no. But at the same time display the correct
value according to the datatable?

Many Thanks
Simon

DataGridView1.Columns(0).Visible = False

DataGridView1.Columns(1).Visible = False

DataGridView1.Columns(2).Visible = False

DataGridView1.Columns(3).Visible = False

DataGridView1.Columns(4).Visible = False

'the questionno

Dim QNo As New DataGridViewTextBoxColumn

QNo.HeaderText = "Question No."

QNo.DataPropertyName = "SortNo"

Me.DataGridView1.Columns.Add(QNo)

'the question textbox in the grid

Dim xy As New DataGridViewTextBoxColumn

xy.HeaderText = "Question"

xy.DataPropertyName = "shortDescription"

Me.DataGridView1.Columns.Add(xy)

'drop down list on grid

'Dim xx As New DataGridViewComboBoxColumn

'xx.DataPropertyName = "defaultanswerYN"

'xx.Name = "YesNo"

'xx.Items.Add("Yes")

'xx.Items.Add("No")

'Me.DataGridView1.Columns.Add(xx)

Dim YesNo As New DataGridViewComboBoxColumn

With YesNo

..DataPropertyName = "yesno"

..HeaderText = "Question Answer"

..DataSource = dt

..ValueMember = "yesno"

..DisplayMember = "yesNo"

End With

DataGridView1.Columns.Add(YesNo)

'the Answer Question

Dim yx As New DataGridViewTextBoxColumn

yx.HeaderText = "Answer"

yx.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

yx.DataPropertyName = "SOFTemplateText"

Me.DataGridView1.Columns.Add(yx)

'the view button

' Add a button column.

Dim buttonColumn As New DataGridViewButtonColumn()

buttonColumn.HeaderText = "Requests"

buttonColumn.Text = "Requests"

buttonColumn.UseColumnTextForButtonValue = True

buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells

buttonColumn.FlatStyle = FlatStyle.Standard

DataGridView1.Columns.Add(buttonColumn)
 
C

Cor Ligthert[MVP]

Simon,

Try to avoid Yes No dropdowns, it is mostly a lot of work (you need to
create a usercontrol), while everybody understands a checkbox which is easy
to do.

Cor
 
S

Simon Whale

I can't avoid the yes no dropdowns as its a business requirement for an
insurance back office.


Cor Ligthert said:
Simon,

Try to avoid Yes No dropdowns, it is mostly a lot of work (you need to
create a usercontrol), while everybody understands a checkbox which is
easy to do.

Cor

Simon Whale said:
Hi all,

[vb2008]

I need help with the following, I have a grid that i have put on there 2
textbox's and a combobox column which works ok.

When i then add the data by using the following code below, it works, my
problem is with the combobox "YesNo" it put the complete contents of the
datatable into the combobox for each row. My question is how can i limit
the drop down to 1 yes and 1 no. But at the same time display the
correct value according to the datatable?

Many Thanks
Simon

DataGridView1.Columns(0).Visible = False

DataGridView1.Columns(1).Visible = False

DataGridView1.Columns(2).Visible = False

DataGridView1.Columns(3).Visible = False

DataGridView1.Columns(4).Visible = False

'the questionno

Dim QNo As New DataGridViewTextBoxColumn

QNo.HeaderText = "Question No."

QNo.DataPropertyName = "SortNo"

Me.DataGridView1.Columns.Add(QNo)

'the question textbox in the grid

Dim xy As New DataGridViewTextBoxColumn

xy.HeaderText = "Question"

xy.DataPropertyName = "shortDescription"

Me.DataGridView1.Columns.Add(xy)

'drop down list on grid

'Dim xx As New DataGridViewComboBoxColumn

'xx.DataPropertyName = "defaultanswerYN"

'xx.Name = "YesNo"

'xx.Items.Add("Yes")

'xx.Items.Add("No")

'Me.DataGridView1.Columns.Add(xx)

Dim YesNo As New DataGridViewComboBoxColumn

With YesNo

.DataPropertyName = "yesno"

.HeaderText = "Question Answer"

.DataSource = dt

.ValueMember = "yesno"

.DisplayMember = "yesNo"

End With

DataGridView1.Columns.Add(YesNo)

'the Answer Question

Dim yx As New DataGridViewTextBoxColumn

yx.HeaderText = "Answer"

yx.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells

yx.DataPropertyName = "SOFTemplateText"

Me.DataGridView1.Columns.Add(yx)

'the view button

' Add a button column.

Dim buttonColumn As New DataGridViewButtonColumn()

buttonColumn.HeaderText = "Requests"

buttonColumn.Text = "Requests"

buttonColumn.UseColumnTextForButtonValue = True

buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells

buttonColumn.FlatStyle = FlatStyle.Standard

DataGridView1.Columns.Add(buttonColumn)
 
F

Fred

Simon Whale said:
Hi all,
Hello,

When i then add the data by using the following code below, it works,
my problem is with the combobox "YesNo" it put the complete contents
of the datatable into the combobox for each row. My question is how
can i limit the drop down to 1 yes and 1 no. But at the same time
display the correct value according to the datatable?
With YesNo
.DataPropertyName = "yesno"
.HeaderText = "Question Answer"
.DataSource = dt

It seems that you populate your combo with the same data as your
DataGridView (?)
Just fill your combo with Yes and No and don't bind its content.
 

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