[英]How do you convert a cell value in a DataGridView into a integer if it's an integer, and a string when it's a string?
我有一個名為“ dgvDynamic”的DataGridview,它可以將來自MS Access DB的數據顯示到DataGridView中。 我想在一個名為“ txtSelectedCell”的文本框中顯示所選單元格的值。
但是,它將僅在文本框中顯示字符串數據類型的數據,而不是整數。 如何在文本框中同時顯示字符串和整數? 謝謝。 這是代碼:
Private Sub dgvDynamic_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDynamic.CellContentClick
txtSelectedCell.Text = dgvDynamic.SelectedCells(0).Value.ToString
End Sub
原來我使用了錯誤的事件。 我應該使用“ ClickEvent”,然后更改語句,而不是使用“ CellContent”事件
來自: txtSelectedCell.Text = dgvDynamic.SelectedCells(0).Value.ToString
到: txtSelectedCell.Text = dgvDynamic.CurrentCell.Value.ToString()
感謝@Codex為我解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.