datagrid怎么设置才可以让用户编辑cell中的值,然后将用户编辑后的值保存到数据库中
晕死,现在连datagrid中的值都不可编辑。希望可以得到你们的提示,thanx!我试写过如下代码来让数据库保存用户编辑后的值
Private sub DataGrid1_AfterColEdit(byval ColIndex as integer)
    a$=trim(DataGrid1.clomns(6).cellText(DataGrid1.book))
    if a$<>"" then
        if csn(a$)<>rs(6) then
             rs(6)=csn(a$)
             rs.update
             datagrid1.refresh
        endif
    end if
End SubDataChanged 不知道怎么使用,msdn上的简单说明,好象可以很方便把数据更新到数据库
现在最想知道的是如何让datagrid可以允许用户编辑数据(datagrid是有数据源的)
请高手多指点

解决方案 »

  1.   

    看看DataGrid的AllowUpdate属性是否设置为True了
      

  2.   

    呵呵,设置过了 
    a$=trim(DataGrid1.clomns(6).cellText(DataGrid1.book))
    还有这句出现获取数据出错
    我想控制columns("销售单价")那一列:在用户更改cell中的值时就更新到rs中,然后
    rs.movefirst 
    for i=0 to rs.recordcount-1
        sum=sum+rs(6)
    next i
    label1.caption=cstr(sum)来显示销售总额
      

  3.   

    DataGrid默认就是可编辑的,只要你绑定的记录集不为空,同时记录集对应的是各个列,比如:
    rs.Open "select * from 表",cn,3,2
    Set DataGrid1.DataSource=rs  'DataGrid1可编辑rs.Open "select f1*f2 as [f1*f2],f1+f2 as [f1+f2] from 表"
    Set DataGrid1.DataSource=rs  'DataGrid1不可编辑,因为得到的记录集并不与表的列直接对应
    如果你手动对DataGrid进行过编辑,建议你把它删了,重新添加一个DataGrid再试试
      

  4.   

    a$=trim(DataGrid1.clomns(6).cellText(DataGrid1.book))
    ---------------------------------------
    clomns(6)写错了,是clomns(6),而且DataGrid1至少要有7列,否则出错
      

  5.   

    打错了而已,工作不是vb编程,在公司凭记忆打出来发问谢谢你了,我用了后一种情况
    rs.Open "select f1*f2 as [f1*f2],f1+f2 as [f1+f2] from 表"
    Set DataGrid1.DataSource=rs  'DataGrid1不可编辑,
    因为得到的记录集并不与表的列直接对应