帮助将值从TextBox显示到Datagridview控件 [英] Help On Displaying Values From TextBox To A Datagridview control

查看:125
本文介绍了帮助将值从TextBox显示到Datagridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,其数据源是一个实体集合。我可以使用datagridview SelectionChanged events将所选行的值加载到不同的文本框中.Below是我正在使用的代码。



I have a datagridview whose datasource is an entity collection.I can load the values of the selected rows into different textboxes using the datagridview SelectionChanged events.Below is the code that i am using.

Dim selectedUser = DirectCast(Me.grdShowOfficers.CurrentRow.DataBoundItem, Exams_Officer)
       txtTitle.Text = selectedUser.Title
       txtFirst.Text = selectedUser.First_Name
       txtLastName.Text = selectedUser.Last_Name
       txtFaculty.Text = selectedUser.Faculty.Faculty_Name
       txtDepartment.Text = selectedUser.Department.Department_Name
       txtProgramme.Text = selectedUser.Programme
       txtPhoneNumber.Text = selectedUser.Phone_Number
       dateAppointment.Text = selectedUser.Appointment_Date





工作正常。问题是当我更改文本框的值时,当我从按钮点击事件调用实体saveChanges()方法时,它没有在datagridview上显示已编辑的值。我知道我做错了,我需要帮助。这是按钮点击事件。





It works fine.The problem is that when i change the values of the textbox it is not showing the edited values on the datagridview when i call the entity saveChanges() method from a button click event.I know i am doing something wrong please i need help.This is the button click event.

Dim selectedRow As Int32 = Me.grdShowOfficers.Rows.GetFirstRow(DataGridViewElementStates.Selected)




selectedrow.Title = txtTitle.Text
selectedUser.First_Name = txtFirst.Text
selectedUser.Last_Name() = txtLastName.Text
'selectedUser.Faculty.Faculty_Name = txtFaculty.Text
'selectedUser.Department.Department_Name = txtDepartment.Text
selectedUser.Programme = txtProgramme.Text
selectedUser.Phone_Number = txtPhoneNumber.Text
selectedUser.Appointment_Date = CType(dateAppointment.Text, Date)
    examinationOfficer.SaveChanges()







当我这样做时( datagridview contentdouble click事件下面的代码)




when i do these (the below code ) on the datagridview contentdouble click event

txtTitle.Text = grdShowOfficers.Item("Title", grdShowOfficers.CurrentRow.Index).Value.ToString()
      txtFirst.Text = grdShowOfficers.Item("First_Name", grdShowOfficers.CurrentRow.Index).Value.ToString()
      txtLastName.Text = grdShowOfficers.Item("Last_Name", grdShowOfficers.CurrentRow.Index).Value.ToString()
      txtProgramme.Text = grdShowOfficers.Item("Programme", grdShowOfficers.CurrentRow.Index).Value.ToString()
      txtPhoneNumber.Text = grdShowOfficers.Item("Phone_Number", grdShowOfficers.CurrentRow.Index).Value.ToString()
      dateAppointment.Text = grdShowOfficers.Item("Appointment_Date", grdShowOfficers.CurrentRow.Index).Value.ToString()



和此按钮点击事件在调用savechanges之前


and this button click event before calling savechanges

grdShowOfficers.CurrentCell.Value = txtTitle.Text

        grdShowOfficers.CurrentCell.Value = txtLastName.Text

        grdShowOfficers.CurrentCell.Value = txtFirst.Text

        grdShowOfficers.CurrentCell.Value = txtProgramme.Text

        grdShowOfficers.CurrentCell.Value = txtPhoneNumber.Text

        grdShowOfficers.CurrentCell.Value = dateAppointment.Text



只有所选数据网格行的第一个单元格更新,它获得的值是最后一个单元格的值,该单元格由dateappointment.text文本框更新。请帮助


only the first cell of the selected datagridview row is updated and the value it gets is the value of the last cell which is suppose to be updated by the dateappointment.text textbox.Please help

推荐答案

在按钮单击您正在使用
grdShowOfficers.CurrentCell.Value = ....Text

进行所有更新。

尝试使用类似

for all of your updates.
Try using something like

grdShowOfficers.CurrentRow.Cells("Last_Name").Value = txtLastName.Text

等等


这篇关于帮助将值从TextBox显示到Datagridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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