Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to Assign Value to Boundtext in DataGridViewComboBoxColumn
 

How to Assign Value to Boundtext in DataGridViewComboBoxColumn

hello, i am creating column of DataGridViewComboBoxColumn and binding it.
it working fine.

but when i fill the grid manually it not shows me value...

in the DataGrdcombo
Ramesh Addagatla  Wednesday, August 26, 2009 12:49 PM

Hi,

If comboboxcolumn.datasource contains the boundtext, this will make comboboxcolumn show the correct display text.

You can try the following example.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'DataGridView datasource

Dim dt01 As DataTable = New DataTable()

dt01.Columns.Add("Mill")

dt01.Columns.Add("tag")

dt01.Rows.Add("01", "test01")

dt01.Rows.Add("02", "test02")

'comboboxcolumn datasource

Dim dt02 As DataTable = New DataTable()

dt02.Columns.Add("DepartmentName")

dt02.Columns.Add("DepartmentID")

dt02.Rows.Add("name01", "01")

dt02.Rows.Add("name02", "02")

DataGridView1.AutoGenerateColumns = False

DataGridView1.DataSource = dt01

Dim Col_Mill As New DataGridViewComboBoxColumn

With Col_Mill

.Name = "Mill"

.DataPropertyName = "Mill"

.DisplayMember = "DepartmentName"

.ValueMember = "DepartmentID"

.DataSource = dt02

.Width = 150

End With

Dim datagridviewtextboxcolumn As New DataGridViewTextBoxColumn

With datagridviewtextboxcolumn

.Name = "tag"

.DataPropertyName = "tag"

End With

DataGridView1.Columns.Add(Col_Mill)

DataGridView1.Columns.Add(datagridviewtextboxcolumn)

End Sub

If you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 01, 2009 10:48 AM
Hi,
How do you bind the data?

Can you present us some code?

Regards,
Vinil;
VinilV  Wednesday, August 26, 2009 1:02 PM
hello,

i am fill the DataGridViewComboBoxColumn Column with mill Details

Dim Col_Mill As New DataGridViewComboBoxColumn
With Col_Mill
.Name = "Mill"
.DataPropertyName = "Mill"
.DisplayMember = "DepartmentName"
.ValueMember = "DepartmentID"
.DataSource = DB.GetDT(String.Format("Select DepartmentID, DepartmentName From {0} Where ServiceID = {1}", Db_Detials.tbl_DepartmentMaster, Localization.ParseNativeInt(Db_Detials.ComboType.Mill)), False)
.Width = 150
End With
DataGridview1.Columns.Add(Col_Mill)


but on navigating records i have to set the DepartmentID to the boundtext column that is .ValueMembers so how can i do that????
Ramesh Addagatla  Saturday, August 29, 2009 5:10 AM

Hi,

If comboboxcolumn.datasource contains the boundtext, this will make comboboxcolumn show the correct display text.

You can try the following example.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'DataGridView datasource

Dim dt01 As DataTable = New DataTable()

dt01.Columns.Add("Mill")

dt01.Columns.Add("tag")

dt01.Rows.Add("01", "test01")

dt01.Rows.Add("02", "test02")

'comboboxcolumn datasource

Dim dt02 As DataTable = New DataTable()

dt02.Columns.Add("DepartmentName")

dt02.Columns.Add("DepartmentID")

dt02.Rows.Add("name01", "01")

dt02.Rows.Add("name02", "02")

DataGridView1.AutoGenerateColumns = False

DataGridView1.DataSource = dt01

Dim Col_Mill As New DataGridViewComboBoxColumn

With Col_Mill

.Name = "Mill"

.DataPropertyName = "Mill"

.DisplayMember = "DepartmentName"

.ValueMember = "DepartmentID"

.DataSource = dt02

.Width = 150

End With

Dim datagridviewtextboxcolumn As New DataGridViewTextBoxColumn

With datagridviewtextboxcolumn

.Name = "tag"

.DataPropertyName = "tag"

End With

DataGridView1.Columns.Add(Col_Mill)

DataGridView1.Columns.Add(datagridviewtextboxcolumn)

End Sub

If you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 01, 2009 10:48 AM

You can use google to search for other answers

Custom Search

More Threads

• About ComboBox in DOTNET (Windows Application C#)
• Adding Image to the DataGridView editing column
• DataTables
• 2 Bounds DataGridViewComboBoxColumn - Select value from the first should filter the second !
• adding multiple controls in DataGridViewColumn
• Extra steps needed when saving rows
• Change cell color in a DataGridView CellValidating event?
• DataGridView first row
• Strange behavior in datagridview when adding data to dataset
• Export Data From a DataGrid in a ASP Web Application