9 Replies - 16756 Views - Last Post: 23 March 2012 - 11:47 AM Rate Topic: -----

#1 cry4you  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 09-October 09

Change datagridview column to combobox VB

Posted 23 March 2012 - 10:40 AM

Hello.

I have generated datagridview column dinamicly by code

 DataSet1.Clear()
        SqlDataAdapter1.Fill(DataSet1.Tables(0))
        DataGridView1.DataSource = DataSet1.Tables(0)


And i would like to put in existing column combobox.
I have found alot of tutorials about how to add column as combobox
  Dim cmb As New DataGridViewComboBoxColumn()
        cmb.HeaderText = "Select Data"
        cmb.Name = "cmb"
        cmb.MaxDropDownItems = 4
        cmb.Items.Add("True")
        cmb.Items.Add("False")
        DataGridView1.Columns.Add(cmb)


But i need code something like
DataGridView1.Columns(Person_hair_cut).Add(cmb)



Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Change datagridview column to combobox VB

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 10:50 AM

you mean you want to add columns straight up?

DataGridView1.Columns.Add("<column name>", "<header text>")

Was This Post Helpful? 0
  • +
  • -

#3 cry4you  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 09-October 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 10:52 AM

View PostnK0de, on 23 March 2012 - 10:50 AM, said:

you mean you want to add columns straight up?

DataGridView1.Columns.Add("<column name>", "<header text>")


No No No i want to change existing column type to combobox, not to add.
Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 10:55 AM

Ah okay. The only method I know for that is the one you've already found.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:11 AM

Are you talking something like:

Dim cboColumn as new DataGridViewComboboxColumn
cboColumn.Name = "cmb"
cboColumn.HeaderText = "Person_Hair_Cut"

dgv1.Columns.Add(cboColumn)

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:18 AM

I see now you already had that method of creation, sorry :(

Anyway, why is it you need it to be like you're showing at the bottom of your code?
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:34 AM

Wait, are you trying to add items to the combobox after it's created?

Something like
dim cbo as DataGridViewComboBoxColumn = CType(DataGridView1.Columns.Items("Person_Hair_Cut"), DataGridViewComboboxColumn

cbo.Items.Add("Maybe")
cbo.Items.Add("Undecided")


This would add 2 more items to what you had in your original combobox items so you would then have
True
False
Maybe
Undecided
Was This Post Helpful? 0
  • +
  • -

#8 cry4you  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 09-October 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:37 AM

View PostCharlieMay, on 23 March 2012 - 11:18 AM, said:

I see now you already had that method of creation, sorry :(

Anyway, why is it you need it to be like you're showing at the bottom of your code?


The datagridview columns are generated automatically from database by sqldataAdapter and everyting works fine.
And i just wanted to improve the program by changing column to combobox.
Was This Post Helpful? 0
  • +
  • -

#9 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:45 AM

You mean like adding normal columns like this, DataGridView1.Columns.Add("<column name>", "<header text>")
, you need a shorter way to add columns with different column types?
Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Change datagridview column to combobox VB

Posted 23 March 2012 - 11:47 AM

ah, I see.
Well, from what I'm reading you can't change it as it's bound but you can add a new column as a combobox and remove the old one. Not sure if that would help in your situation but here is an example
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1