在使用特定行的数据集加载特定datagridview组合框列时出现问题 [英] Problem loading a specific datagridview combo-box column with a dataset for a specific row
问题描述
我目前正在Windows应用程序上使用datagridview.我有两个特定的列,它们将相互配合工作.为简单起见,第1列用于选择许可证编号,第2列用于选择许可名称(这些列均为组合框列).当最终用户选择一个名称时,我将根据该特定行的所选人员的ID向许可证编号组合框加载数据集.这将加载分配给该特定人员的所有许可证号.在测试我的代码时,数据集将根据所选人员正确加载.问题:datagridview希望使用该特定数据集加载第1列中的每行.我只希望最终用户当前正在使用的特定行号具有此数据集加载列1.
我目前正在使用以下代码进行测试:
I''m currently working with a datagridview on a windows application. I have two specific columns which will work alongside each other. For simplicity, column 1 is used to select a license number, column 2 is used to select a licensed name (both of these columns are combo-box columns). When the end-user selects a name, I''m loading the license number combo-box with a data-set according to the ID of the person selected, for that particular row. This will load any license number(s) assigned to that specific person. While testing my code, the data-set loads correctly according to the person selected. Issue: The datagridview wants to load every row in column 1 with that specific data-set. I would like to have this data-set load column 1 only for the specific row number which the end-user is currently working with.
My code I''m currently testing with:
Private Sub grdvwDeposit_CellValueChanged(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles grdvwDeposit.CellValueChanged
If IsComboBoxCell(e) Then
If e.ColumnIndex = 2 Then
Call SetLicenseComboBoxes(e)
End If
End If
End Sub
Private Sub SetLicenseComboBoxes(ByVal e As DataGridViewCellEventArgs)
Dim intVal As Integer
Dim objWork As Object = Nothing
Dim cur_cell As DataGridViewCell = Me.grdvwDeposit.CurrentCell
Dim row As Integer = cur_cell.RowIndex
Dim col As Integer = cur_cell.ColumnIndex
If Me.grdvwDeposit.CurrentCell.ColumnIndex = 2 Then
objWork = Me.grdvwDeposit.Rows(row).Cells(col).Value
If IsNumeric(objWork) Then
intVal = CInt(objWork)
Else
Exit Sub
End If
Dim intRow As Integer = row
Do Until intRow = row - 1
Call FillDataSet(mdsLicenseSpecific,
"usp_tblTransaction_Grid_License_FillComboBox_Specific",
"@ID_Person", intVal)
Try
Call FillMassTransactionGridViewComboBoxFromDataset
(Me.grdvwDeposit.Rows(row),
Me.grdvwDeposit.Columns(1),
mdsLicenseSpecific)
Catch ex As Exception
MessageBox.Show(ex.ToString, gstrAppName,
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
intRow -= 1
Loop
Exit Sub
End If
End Sub
在我的执行至未完成"代码中,您可以看到我正在根据使用的当前行加载特定的行和列.任何建议将不胜感激.
谢谢,
GoBrvs01
In my ''Do-Until'' code, you can see that I''m loading a specific row and column, according to the current row being used. Any suggestions would be greatly appreciated.
Thanks,
GoBrvs01
推荐答案
在我看来,代码中的Do...Loop
循环是不必要的.
在我的表单上,我在列中放置了DataGridView1
:
价格-DataGridViewTextBoxColumn
总价格-DataGridViewTextBoxColumn
DataGridView1
允许编辑单元格.
下面的代码显示如何在特定行中更新TotalPrice:
In my opinionDo...Loop
loop in your code is unneccessary.
On my form i''ve placedDataGridView1
with columns:
Price -DataGridViewTextBoxColumn
TotalPrice -DataGridViewTextBoxColumn
DataGridView1
allow to edit cells.
Below code shows how to update TotalPrice in a specific row:
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
'cell in a first column was updated?
If e.ColumnIndex = 0 Then UpdateTotalPrice(e.RowIndex)
End Sub
Sub UpdateTotalPrice(ByVal iRow As Integer)
'if no data ;)
If iRow = -1 Then Exit Sub
Dim price As Double = Me.DataGridView1.Rows(iRow).Cells("Price").Value
Me.DataGridView1.Rows(iRow).Cells("TotalPrice").Value = price * 1.22 '+ 22%
End Sub
这篇关于在使用特定行的数据集加载特定datagridview组合框列时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!