立即显示值,而不是单击任何单元格 [英] Showing values instantly rather than clicking any cell

查看:89
本文介绍了立即显示值,而不是单击任何单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码显示课程数的总数 在TextBox1中(代码也执行其他操作).现在,当我在 课程数列,它不会立即添加.仅当我单击任意一个单元格时,它才会显示.但是我想立即显示总计值(当我输入它们时,而不是单击任何单元格之后).我怎样才能做到这一点?我应该使用其他 事件?我在下面添加了一些屏幕截图.

I am using the following codes to show total of Number of Courses in the TextBox1 (the code performs other things too). Now when I input values in the NumberofCourses column, it does not add instantly. It shows only when I click any one of the cells. But I want to show the total values instantly (when I input them, not after clicking any of the cells). How can I do that? Should I use different event? I added few screenshots below. 

Private Sub dg1FrmCourseNumber_CellStateChanged(sender As Object, e As DataGridViewCellStateChangedEventArgs) Handles dg1FrmCourseNumber.CellStateChanged
        On Error Resume Next
        Dim totalCourse, j, k, CoursetoRed, CoursetoIncr As Short
        j = CShort(dg1FrmCourseNumber.RowCount - 1)
        totalCourse = 0
        For k = 0 To j
            totalCourse = totalCourse + CShort(CStr(dg1FrmCourseNumber.Rows(k).Cells(4).Value.ToString))
        Next
        TextBox1.Text = totalCourse.ToString
        CoursetoRed = CShort((Int(totalCourse / CShort(TextBox2.Text)) * CShort(TextBox2.Text)) - totalCourse)
        CoursetoIncr = CShort(TextBox2.Text) + CoursetoRed
        Label3.Text = "Course Adjustment: Reduce " & CoursetoRed * (-1) & " Or Increase " & CoursetoIncr.ToString & " Courses"
    End Sub



失败

推荐答案

您可以在此链接 DataGridView类,并确定要使用的事件.

You can view the events available for DataGridView at this link DataGridView Class and determine which event to use.

也许是CellLeave,CellMouseLeave,CellValueChanged或任何可行的方法.如果这是您更改单元格中信息的方式,则可能需要以编程方式结束单元格编辑,以使CellValue发生更改,或者在发生CellLeave或CellMouseLeave时进行更改.

Maybe CellLeave, CellMouseLeave, CellValueChanged or whichever works. Possibly you need to programmatically end cell edit if that is how you alter information in cell so the CellValue changes or whatever when CellLeave or CellMouseLeave occurs.


这篇关于立即显示值,而不是单击任何单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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