Datagridview将Datetime转换为String [英] Datagridview converting Datetime to String
本文介绍了Datagridview将Datetime转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将datagridview项目(datetime格式)转换为字符串。
How to convert datagridview item (datetime format) to string.
这是我的代码:
ComboBox1.Text = DatagridView1.Item(4, 1).Value.ToString()
有人能帮我吗?这是完整的代码:
Can someone help me? This is the full code:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
btnEdit.Visible = True
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim x As String = CStr(DataGridView1.Item(4, i).Value.ToString)
Dim y As String = CStr(DataGridView1.Item(5, i).Value.ToString)
MsgBox(x)
MsgBox(y)
txtTrainID.Text = DataGridView1.Item(0, i).Value
txtRouteID.Text = DataGridView1.Item(1, i).Value
txtLine.Text = DataGridView1.Item(2, i).Value
cmbLine1.Text = DataGridView1.Item(3, i).Value
cmbLine2.Text = DataGridView1.Item(3, i).Value
cmbLine3.Text = DataGridView1.Item(3, i).Value
cmbTS.Text = x.ToString
cmbTA.Text = y.ToString
txtTrainName.Text = DataGridView1.Item(6, i).Value
cmbFlag.Text = DataGridView1.Item(7, i).Value
End Sub
推荐答案
如果要显示值
到 ComboBox
属性必须设置为 DropDownStyle = DropDown
和你不需要这个 i = DataGridView1.CurrentRow.Index
来获取 currentRowIndex
> code> DataGridView CellClick事件
If you want to display the Value
to ComboBox
the property must set as DropDownStyle = DropDown
and you don't need this i = DataGridView1.CurrentRow.Index
to get the currentRowIndex
of the DataGridView
in CellClick event
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
ComboBox1.Text = DatagridView1.Item(4, e.RowIndex).Value.ToString()
End Sub
这篇关于Datagridview将Datetime转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文