用于 winforms 的 telerik radgridview 中的组合框
Combobox in telerik radgridview for winforms
我正在尝试在 telerik gridview 中嵌入一个组合框,但它甚至没有加载到网格中。
我正在尝试使用存储过程从数据库中的 table 中获取值。
我的代码版本如下:
Private Sub GetDocType()
Try
Dim db As New gpcdb.dbaccess
Dim cmd As New SqlClient.SqlCommand
cmd = db.GetSqlDBCmd("gpc_DocumentType", CommandType.StoredProcedure)
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Open()
ddlDocType.ValueMember = "gpcDocTypeID"
ddlDocType.DisplayMember = "docType"
ddlDocType.DataSource = cmd.ExecuteReader
cmd.Connection.Close()
'grdDragDoc.Rows(9)
db = Nothing
cmd = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub grdDragDoc_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdDragDoc.CellEditorInitialized
Dim db As New gpcdb.dbaccess
Dim cmd As New SqlClient.SqlCommand
cmd = db.GetSqlDBCmd("gpc_DocumentType", CommandType.StoredProcedure)
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Open()
ddlDocType.ValueMember = "gpcDocTypeID"
ddlDocType.DisplayMember = "docType"
ddlDocType.DataSource = cmd.ExecuteReader
cmd.Connection.Close()
If e.Column.Name = "ddlDocType" Then
Dim editor As RadDropDownListEditor = TryCast(Me.grdDragDoc.ActiveEditor, RadDropDownListEditor)
If Not editor Is Nothing Then
CType((CType(Me.grdDragDoc.ActiveEditor, RadDropDownListEditor)).EditorElement, RadDropDownListEditorElement).RightToLeft = True
End If
End If
'grdDragDoc.Columns.Add(ddlDocType)
'grdDragDoc.Rows(9)
db = Nothing
cmd = Nothing
End Sub
Private Sub grdDragDoc_CellValueChanged(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdDragDoc.CellValueChanged
Try
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
'If e.ColumnIndex = ddlDocType.Index Then
Dim retreivedValue As Object = grdDragDoc.Rows(grdDragDoc.CurrentRow.Index).Cells(9)
Catch ex As Exception
End Try
End Sub
Private Sub DocumentListLoad()
Try
Dim objDoc As New gpcdb.document
Dim cmd As New SqlClient.SqlCommand
cmd = objDoc.DocumentList(_ClientID)
cmd.Connection.Open()
grdDragDoc.LoadFrom(cmd.ExecuteReader(CommandBehavior.CloseConnection))
'lstDocuments.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
'Assign drop down list to column in the grid
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Close()
cmd = Nothing
objDoc = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "DocumentListLoad", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
在这里您可以看到如何在 RadGridView 中设置组合框列:http://www.telerik.com/help/winforms/gridview-columns-gridviewcomboboxcolumn.html
GridViewComboBoxColumn supplierColumn = new GridViewComboBoxColumn();
supplierColumn.Name = "SupplierColumn";
supplierColumn.HeaderText = "Supplier";
supplierColumn.DataSource = this.suppliersBindingSource;
supplierColumn.ValueMember = "SupplierID";
supplierColumn.DisplayMember = "ContactName";
supplierColumn.FieldName = "SupplierID";
supplierColumn.Width = 200;
this.radGridView1.Columns.Add(supplierColumn);
我正在尝试在 telerik gridview 中嵌入一个组合框,但它甚至没有加载到网格中。
我正在尝试使用存储过程从数据库中的 table 中获取值。
我的代码版本如下:
Private Sub GetDocType()
Try
Dim db As New gpcdb.dbaccess
Dim cmd As New SqlClient.SqlCommand
cmd = db.GetSqlDBCmd("gpc_DocumentType", CommandType.StoredProcedure)
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Open()
ddlDocType.ValueMember = "gpcDocTypeID"
ddlDocType.DisplayMember = "docType"
ddlDocType.DataSource = cmd.ExecuteReader
cmd.Connection.Close()
'grdDragDoc.Rows(9)
db = Nothing
cmd = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub grdDragDoc_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdDragDoc.CellEditorInitialized
Dim db As New gpcdb.dbaccess
Dim cmd As New SqlClient.SqlCommand
cmd = db.GetSqlDBCmd("gpc_DocumentType", CommandType.StoredProcedure)
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Open()
ddlDocType.ValueMember = "gpcDocTypeID"
ddlDocType.DisplayMember = "docType"
ddlDocType.DataSource = cmd.ExecuteReader
cmd.Connection.Close()
If e.Column.Name = "ddlDocType" Then
Dim editor As RadDropDownListEditor = TryCast(Me.grdDragDoc.ActiveEditor, RadDropDownListEditor)
If Not editor Is Nothing Then
CType((CType(Me.grdDragDoc.ActiveEditor, RadDropDownListEditor)).EditorElement, RadDropDownListEditorElement).RightToLeft = True
End If
End If
'grdDragDoc.Columns.Add(ddlDocType)
'grdDragDoc.Rows(9)
db = Nothing
cmd = Nothing
End Sub
Private Sub grdDragDoc_CellValueChanged(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdDragDoc.CellValueChanged
Try
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
'If e.ColumnIndex = ddlDocType.Index Then
Dim retreivedValue As Object = grdDragDoc.Rows(grdDragDoc.CurrentRow.Index).Cells(9)
Catch ex As Exception
End Try
End Sub
Private Sub DocumentListLoad()
Try
Dim objDoc As New gpcdb.document
Dim cmd As New SqlClient.SqlCommand
cmd = objDoc.DocumentList(_ClientID)
cmd.Connection.Open()
grdDragDoc.LoadFrom(cmd.ExecuteReader(CommandBehavior.CloseConnection))
'lstDocuments.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
'Assign drop down list to column in the grid
Dim ddlDocType As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
cmd.Connection.Close()
cmd = Nothing
objDoc = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "DocumentListLoad", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
在这里您可以看到如何在 RadGridView 中设置组合框列:http://www.telerik.com/help/winforms/gridview-columns-gridviewcomboboxcolumn.html
GridViewComboBoxColumn supplierColumn = new GridViewComboBoxColumn();
supplierColumn.Name = "SupplierColumn";
supplierColumn.HeaderText = "Supplier";
supplierColumn.DataSource = this.suppliersBindingSource;
supplierColumn.ValueMember = "SupplierID";
supplierColumn.DisplayMember = "ContactName";
supplierColumn.FieldName = "SupplierID";
supplierColumn.Width = 200;
this.radGridView1.Columns.Add(supplierColumn);