filling a column in datagridview that has type combobox

aakbar

Member
Joined
Mar 7, 2007
Messages
6
Programming Experience
Beginner
Hi I want to fill a column in datagridview that is of type combobox.
can you please guide me how to do it.
i am getting the column using this
VB.NET:
Dim aa As DataGridViewComboBoxColumn
aa = gridQuestions.Columns.Item(1)

but dont know what to do further.
I need to fill all the comboboxes with four option that i have with me.

thanks
 
Last edited by a moderator:
VB.NET:
aa.Items.AddRange("option1", "option2", "option3", "option4")
or
VB.NET:
aa.DataSource = ds1.tables(1234)
 
how to set one item selected in all the combos

Hi,

now i want to select one particular value to selected in all the comboboxes
is there some thing similar which can help to select on choice for whole column in one go.

thanks
 
VB.NET:
aa.DefaultCellStyle.NullValue = "option2"
 
its not working

Hi John apparently it seems to be working fine but this code restricts the user to select the "option2".
as we made the "option2" as null value so even this option is selected in the combo box when we try to get the value from cell it gives nothing.

the way i am thinking to solve it is, to have an option named "please select" so it would be shown to user and user have to have select some thing else.

but orignally this was not my goal, what i was trying to do,
a value is selected by default and user can go forward without changing it if he likes.
 
It doesn't restrict me from selecting the other options when I use the code.

Look into the documentation for the DataGridViewCellStyle class and see what NullValue property means, also check DataSourceNullValue while you are there. In short NullValue is what is displayed if the true value is Null. DataSourceNullValue is the value saved to datasource when the true value is Null.
 
Back
Top