簡體   English   中英

如何僅從DataGridView中獲取小數位數的價格值的整數?

[英]How to get only the Whole Number of a Price Value in Decimal from a DataGridView?

我有一個用於價格的SQL查詢,該查詢在帶小數的DataGridView上顯示它,例如(500.00),但是price列的原始數據類型是整數,因此我必須在SQL查詢中加以補充。 這種情況是當我從DataGridView到TextBox獲取值時,它將帶有小數點的整個值都獲取到TextBox。 我希望發生的是,它忽略小數點,而只獲得價格的整數。 (500.00-DataGridView)(500-文本框)

這是我的代碼:

Private Sub BilliardItemGrid_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles BilliardItemGrid.CellClick // this is the DataGridView Cell Click function

    If e.RowIndex >= 0 Then
        Dim row As DataGridViewRow

        row = Me.BilliardItemGrid.Rows(e.RowIndex)

        Inventory.load_itemtypebilliard(Inventory_EditBothItem.ComboBox1)
        Inventory_EditBothItem.TextBox3.Text = row.Cells("ID").Value.ToString
        Inventory_EditBothItem.TextBox1.Text = row.Cells("Barcode ID").Value.ToString
        Inventory_EditBothItem.Label16.Text = row.Cells("Barcode ID").Value.ToString
        Inventory_EditBothItem.TextBox2.Text = row.Cells("Name").Value.ToString
        Inventory_EditBothItem.ComboBox3.Text = "Billiard"
        Inventory_EditBothItem.Label18.Text = "Billiard"
        Inventory_EditBothItem.ComboBox1.Text = row.Cells("Type").Value.ToString
        Inventory_EditBothItem.Label17.Text = row.Cells("Type").Value.ToString
        Inventory_EditBothItem.TextBox4.Text = row.Cells("Price").Value.ToString // this is how I get the value of the price from the DataGridView to a TextBox
        Inventory_EditBothItem.Label15.Text = row.Cells("Price").Value.ToString // this is how I get the value of the price from the DataGridView to a Label
        Inventory_EditBothItem.TextBox5.Text = row.Cells("Quantity").Value.ToString
        Inventory_EditBothItem.TextBox6.Text = row.Cells("Critical").Value.ToString
        Inventory_EditBothItem.DateTimePicker1.Text = row.Cells("Date Modified").Value.ToString
        Inventory_EditBothItem.ComboBox2.Text = row.Cells("Status").Value.ToString
        Inventory_EditBothItem.TextBox8.Text = row.Cells("Description").Value.ToString

        Inventory.load_givenid()


    End If

    If Inventory_EditBothItem.TextBox1.Text = Nothing Then
        MetroMessageBox.Show(Me, "Select a Billiard Item First", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else

        Inventory_EditBothItem.ShowDialog()

        If Inventory_EditBothItem.Visible = False Then
            Inventory.load_billiarditemtable(BilliardItemGrid)
            Inventory.load_bowlingitemtable(BowlingItemGrid)
            Inventory.load_allitemtable(AllItemGrid)
            Store.load_itemstoretable(ItemStoreGrid)
            Reports.load_itemlisttable(ItemTransactionGrid, ItemTransactionComboBoxInDemand)
            Reports.load_audittable(AuditGrid, AuditComboBoxUser, AuditComboBoxType, AuditDateTimePicker1, AuditDateTimePicker2, AuditRadioButtonAll, AuditRadioButtonSpecDate)
        End If

    End If

End Sub

嘗試轉換為整數。

Inventory_EditBothItem.TextBox4.Text = CInt(row.Cells("Price").Value).ToString
Inventory_EditBothItem.Label15.Text = CInt(row.Cells("Price").Value).ToString 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM