在数据网格视图上编辑 [英] edit on data grid view

查看:79
本文介绍了在数据网格视图上编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我创建了一个Windows窗体应用程序,其中有一个gridview和一个名为保存数据"的按钮.
我在gridview中有三列分别名为formno,学生姓名和地址,..

从网格视图,我想在创建到数据库的表中插入多行.直到这里我完成.
现在,我的问题是验证ach列,如表格No.所示.列用户只能输入数值,而在学生姓名列上,用户可以输入字母.我不知道我会怎么...
请帮助我!

hello everyone,
i have created a windows forms application where i have a gridview and a button named Save Data.
i have three column in gridview named formno, student name and address respectively,..

from the grid view i want to insert multiple rows into the table created into the database. TILL HERE I DONE THIS.
now, my problem is to validate ach column like in form no. column user can enter only numeric value and on the student name column, user can enter on aplhabetical character. i don''t know how would i....
please help me!

推荐答案

您要应用此验证,然后
使用gridview按键事件

并写下这样的代码
you want apply this validation then
use gridview key press event

and write down code like this
 if (gv.currentcell.columnindex==0) //name for alphabets only
{
     if (!(Char.IsLetter(e.KeyChar) == true ||(e.KeyChar)==8))
               {

                                e.cancel = true;

               }
}
else if (<pre lang="cs">gv.currentcell.columnindex==1)//for numeric values only
{
if (!(Char.IsDegit(e.KeyChar) == true ||(e.KeyChar)==8))
               {

                                e.cancel = true;

               }
}
.
.
.



祝您编码愉快!
:)



Happy Coding!
:)



试试吧.......



Hi
try it.......



Private Sub datagridview1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgv_view.EditingControlShowing
        '---restrict inputs
        Dim tb As TextBox
        tb = CType(e.Control, TextBox)

        If DataGridView1.CurrentCell.ColumnIndex = 1 Then
            tb.AutoCompleteCustomSource = scAutoComplete
        End If
    End Sub

    ' then take textbox keypress event

    Private Sub TextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.KeyChar = Allowchars(e.KeyChar)
    End Sub

    'then take textbox keypress event

    Private Sub TextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.KeyChar = Allowchars(e.KeyChar)
    End Sub


您好,
试试吧......

Gridview1.editindex = e.neweditindex;
Binddata();

最好的问候
panduu.
Hi,
Try it....

Gridview1.editindex=e.neweditindex;
Binddata();

Best Regards
panduu.


这篇关于在数据网格视图上编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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