Click here to Skip to main content
14,981,532 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys..
i have adatagrid with DataGridComboBoxColumn and i want to fill this combobox with two items ,
can any one hwlp me in doing that
thanks<b></b>
Posted
Updated 9-Nov-18 1:42am

You define the ItemsSource for the combo box.

Here's one example http://blogs.msdn.com/b/vinsibal/archive/2008/10/31/wpf-datagrid-datagridcomboboxcolumn-v1-intro.aspx[^]
   
Public Property Warehouse() As ObservableCollection(Of String)
Function loadWarehouse()
Dim a As String
Dim dbConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
Dim ConString As String = ConfigurationManager.ConnectionStrings("CompuTrakwpf.MySettings.CompuTrakDBConnectionString").ConnectionString
dbConn.ConnectionString = ConString : dbConn.Open()
Dim DSet As New DataSet, SQLStr As String
Dim cmd As System.Data.SqlClient.SqlCommand
Dim dbAdaptr As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
Dim tRow As DataRow, tTbl As DataTable
Try
With dbAdaptr
.TableMappings.Add("Table", "Warehouse")
SQLStr = "Select [Warehouse] from [Warehouse] order by [Warehouse]"
cmd = New System.Data.SqlClient.SqlCommand(SQLStr, dbConn)
cmd.CommandType = CommandType.Text
.SelectCommand = cmd
.Fill(DSet)
.Dispose()
End With
DSet.AcceptChanges()
tTbl = DSet.Tables.Item(0)
DSet.Dispose() : dbConn.Close()
Warehouse = New ObservableCollection(Of String)() From {""}
For Each tRow In tTbl.Rows
a = (tRow("Warehouse").ToString)
Warehouse.Add(a)
Next
Return 0
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Function


<DataGridComboBoxColumn x:Name="cboWarehouse" Header="Warehouse" Width="70" SelectedItemBinding="{Binding WareHouse}"/>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900