如何将datagridview项目(日期时间格式)转换为字符串。
这是我的代码:
ComboBox1.Text = DatagridView1.Item(4, 1).Value.ToString()
有人能帮助我吗?这是完整的代码:
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
答案 0 :(得分:0)
如果您要将Value
显示为ComboBox
,则必须将该属性设置为DropDownStyle = DropDown
,并且您不需要i = DataGridView1.CurrentRow.Index
来获取currentRowIndex
} DataGridView
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