Datagridview - 双击时增加数字 [英] Datagridview - increment number on double click

查看:103
本文介绍了Datagridview - 双击时增加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 - 我有一个应用程序,它将预设引用(字符串)添加到数据网格视图中的单元格。用户双击第一个单元格(始终在同一列中),第一个单元格将是 - PRG_152_858_ n ,其中 n 是每个双数递增的数字点击一个新的单元格 - 我们从1开始。



我的代码工作得很好,因为它在第一次双击时添加PRG_152_858_1但我无法获得增量工作,我可以看看它为什么不...因为每次执行子时,增量声明都会将数字设置回1.如果我将声明留作dim i作为整数,结果单元格条目将是PRG_152_858_0。



任何人都可以指导我找到正确的解决方案吗?



谢谢

David

Hi - I have an application that adds a pre-set reference (a string) to a cell in a data grid view. The user double clicks on the first cell (always in the same column) where the first reference is to be - "PRG_152_858_n" where n is a number incrementing on each double click in a new cell - we start at 1.

The code I have works fine in that it adds "PRG_152_858_1" on the first double click but I cannot get the increment to work and I can see why it doesn't...because every time the sub is executed, the increment declaration sets the number back to 1. If I leave the declaration as just "dim i as integer", the resulting cell entry will be "PRG_152_858_0".

Can anyone guide me toward the correct solution please?

Thanks
David

Private Sub DataGridView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseDoubleClick
       Dim i As Integer = 1 'This is the incrementing part of the entry
       Dim Inc As String = txtCurFormat.Text 'refers to the first part of the entry dealt with elsewhere
       DataGridView1.SelectedCells.Item(1).Value = Inc & i
       i = i + 1

   End Sub

推荐答案

破解它!!!



用全局变量替换了i局部变量,现在看起来工作正常。
Cracked it!!!

replaced the i local variable with a global variable and it now seems to work OK.


这篇关于Datagridview - 双击时增加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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