datagridview填充问题 [英] datagridview filling problem

查看:55
本文介绍了datagridview填充问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个datagridview有一些列.第一列是一个组合框,因此当我从组合框中选择一个值时,我希望其他列根据第一个选择填充适当的值.如何在vb.net中执行此操作?

目的是创建发票申请.

谢谢您的帮助.

所以这是我一段时间后想出的.有人可以帮助我修复它并使它更稳定吗?因为我知道这是错误的,但是我无法修复.
首先,我在组合框中选择了一个值,然后将发生以下情况:

Hey guys,

I have a datagridview that has some columns. The first column is a combobox so when I select a value from the combobox, I want other columns to fill with the appropriate value depending on the first selection. How can I do this in vb.net?

The purpose of this is to create an invoice application.

Thank you for your help.

So this what I came up with after some time. Can anybody help me fix it and make it more stable? Because I know it is wrong, but I cannot fix it.
First I selected a value in the combobox, then this is what will happen after that:

Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
    Try
      If e.ColumnIndex = 0 Then

   'using the datatable to fill the rest of the columns
         DataGridView1.Item(2, e.RowIndex).Value = dt.Rows.Item(index).Item("Description")
         DataGridView1.Item(3, e.RowIndex).Value = dt.Rows.Item(index).Item("Listprice")

      ElseIf e.ColumnIndex = 1 Then
                                                            
            DataGridView1.Item(4, e.RowIndex).Value = CDec(DataGridView1.Item(1, e.RowIndex).Value) * CDec(DataGridView1.Item(3, e.RowIndex).Value)

       ElseIf e.ColumnIndex = 3 Then

            DataGridView1.Item(4, e.RowIndex).Value = CDec(DataGridView1.Item(1, e.RowIndex).Value) * CDec(DataGridView1.Item(3, e.RowIndex).Value)
            End If
        Catch
        End Try

    End Sub

  Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
       
 If (TypeOf e.Control Is DataGridViewComboBoxEditingControl) Then

      Dim comboControl As DataGridViewComboBoxEditingControl = CType(e.Control, DataGridViewComboBoxEditingControl)
      comboControl.DropDownStyle = ComboBoxStyle.DropDown

            Dim c As ComboBox = CType(e.Control, ComboBox)
             
             'retreiving the selected index
            index = c.SelectedIndex
        End If

 End Sub



谢谢,问候.



Thank you, regards.

推荐答案

您的问题不清楚到底是什么问题吗?
Your question is not clear what exactly is wrong ?


这篇关于datagridview填充问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆