473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataGridView... defaults to DataGridViewTextBoxColumn

When you programmatically bind data to a DataGridView (VS2005), the
resulting columns are DataGridViewTextBoxColumns. Instead of that, i'd
like it to be a DataGridViewComboBoxColumn. How can I do this?

Thanks for the help!
John

Jan 12 '06 #1
2 4503
Hi,

Here is a quick example.
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("Names")
dt.Columns.Add("Name")
dt.Columns.Add("State")
dt.LoadDataRow(New Object() {"Ken Tucker", "Florida"}, True)
dt.LoadDataRow(New Object() {"Cor Ligthert", "Netherlands"}, True)
dt.LoadDataRow(New Object() {"Terry Burns", "United Kingdom"}, True)
dt.LoadDataRow(New Object() {"Armin Zignler", "Germany"}, True)
dt.LoadDataRow(New Object() {"Herfried K. Wagner", "Austria"}, True)
dt.LoadDataRow(New Object() {"Jay B Harlow", "New York"}, True)
DataGridView1.DataSource = dt
DataGridView1.AllowUserToAddRows = False

DataGridView1.Columns.Remove("State")

Dim dgvCombo As New DataGridViewComboBoxColumn
With dgvCombo
.Width = 150
.Items.Add("Florida")
.Items.Add("Netherlands")
.Items.Add("United Kingdom")
.Items.Add("Germany")
.Items.Add("Austria")
.Items.Add("New York")
.DataPropertyName = "State"
.HeaderText = "State"
End With

DataGridView1.Columns.Add(dgvCombo)
End Sub

Ken
------------------
"johnb41" <js********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
When you programmatically bind data to a DataGridView (VS2005), the
resulting columns are DataGridViewTextBoxColumns. Instead of that, i'd
like it to be a DataGridViewComboBoxColumn. How can I do this?

Thanks for the help!
John

Jan 12 '06 #2
Looks interesting, Ken. This looks like it will work for me. Thanks
very much!

John

Jan 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rob | last post by:
Dear All, I have a class that exposes a few properties. These properties are used in a DataGridView. The code for that is shown bellow. The problem is that I also need to show...
10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
0
by: Nodir Gulyamov | last post by:
Hello All, First of all thanks in advance to everyone who will try to help me. I have Form with TreeView control and DataGridView control. Each TreeNode has its own rows and due to I am placing...
3
by: Art | last post by:
Hi, Forgive me for posting this message in 2 groups -- it appears that the Data Access group isn't very active, so I'm posting again here: I have a DataTable that I want to fill using a...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
2
by: Stephen Costanzo | last post by:
I have: Public Class test Private displayValue As String Private dbType As Integer Property Display() As String Get Return displayValue End Get
0
by: giminera | last post by:
I've got a datagridview that is bound to a table "orders" of my db. There are 5 column: 4 textcolumn and 1 imagecolumn: code (textcolumn) search (imagecolumn) description (textcolumn) UM...
0
by: frostbb | last post by:
Ok, stumped one more time, I'm trying to learn how to use a DataGridView in place of the old DataGrid control. QUESTION: How do I map the columns returned from a RunTime sql query to the columns...
4
by: Claudia Fong | last post by:
I need to add new rows into a datagridview manually.. but when I first added the new row I got an error of: No row can be added to a DataGridView control that does not have columns. Columns must...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.