是用ado+dataGrid做的·····
 搜索了一些帖子都没有确切的答案···
 问题1:DateGrid怎么取得当前被选中的值啊····
  问题2:双击或用一个按钮把选中的值赋给一个文本编辑框,要怎么做啊····
   问题3:新增记录成功之后怎么刷新让它在DateGrid列表中显示呢····
本人是初学者,请大哥们指点·····
 谢谢啦······

解决方案 »

  1.   

    DataGrid没用过用MSHFlexGrid吧,也可以绑定而且好控制,还可以合并单元格,指定不同颜色
      

  2.   

    void CDlgRecordset::OnButAdd() 
    {
    // TODO: Add your control notification handler code here
    UpdateData();
    m_pRecordset->AddNew();
    m_DataGrid.SetAllowUpdate(true);
    m_DataGrid.Refresh();
    //m_DataGrid.GetDataSource();
    /*BOOL b_tt;
    b_tt=m_DataGrid.GetAllowUpdate();
    int ii, jj; ii = m_DataGrid.GetRow();
    jj = m_DataGrid.GetColumns().GetCount();*/
    }
      

  3.   

    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbcondatagridoverview.asp
      

  4.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dbgrid98/html/vbctlDataGridControl.asp
      

  5.   

    TO:syy64(太平洋)谢谢你····
      能帮我解释下具体怎么用吗···
       我自己弄了下好象没反应·····
        -_-#
      

  6.   

    3
    /// 假定m_pRecordset是一个已经正常打开的记录集
    CDataGrid m_Grid;
    ...
    m_Grid.SetRefDataSource(NULL);
    m_Grid.SetRefDataSource((LPUNKNOWN)m_pRecordset);
    m_Grid.Refresh();http://www.vckbase.com/document/viewdoc/?id=1164
    http://www.codeproject.com/database/msdatagrid.asp
      

  7.   

    SAMPLE: AdoDataGrid.exe Demonstrates How to Use ADO with DataGrid Control Using Visual C++
    http://support.microsoft.com/?kbid=229029&sd=msdn
      

  8.   

    void CAddAward::OnAdd() 
    {
         UpdateData(true);
         _RecordsetPtr   pSet;
         _bstr_t bstrSQL("select * from prize"); 
        pSet.CreateInstance(__uuidof(Recordset)); CString strSQL;
    strSQL.Format("SELECT * FROM prize");
    pSet->Open(COleVariant(strSQL),g_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);

    pSet->AddNew();
    pSet->PutCollect("prizeifile",_variant_t(m_prixefile));
    pSet->PutCollect("price",_variant_t((float)m_price));

    pSet->PutCollect("pcode",_variant_t(m_pcode));
    pSet->PutCollect("iseffect",_variant_t(m_iseffect));
        pSet->Update();
    m_awardGrid.SetRefDataSource((LPUNKNOWN) pSet);//加了这句就报the rowset is not bookable.但是数据已经新增到数据库中去了,这是怎么回事啊,看了一些资料说是要加上“pSet.CreateInstance(__uuidof(Recordset));”,我前面已经加了啊,还要改哪里呢?     m_awardGrid.Refresh();
            AfxMessageBox("添加成功!");
     
    // TODO: Add extra validation here

    }
      

  9.   

    试一下重载ColEdit消息
    void CTestGridDlg::OnColEditDatagrid1(short ColIndex) 
    {
    // TODO: Add your control notification handler code here
    CColumns cols = m_ctrlDG.GetColumns();
    VARIANT vt;
    vt.vt = VT_INT;
    vt.intVal = ColIndex;
    CColumn  col  = cols.GetItem(vt);
    AfxMessageBox(col.GetText());
    }
    要把值赋给编辑框,可以把上面的AfxMessageBox...这行换成
    m_edtCurrent=col.GetText();
    UpdateData(FALSE);
    刷新用m_ctrlDG.UpdateData(FALSE);
      

  10.   

    第一个问题的解决方法
    void CTestGridDlg::OnRowColChangeDatagrid1(VARIANT FAR* LastRow, short LastCol) 
    {
    // TODO: Add your control notification handler code here
    CColumns cols = m_ctrlDG.GetColumns();
    VARIANT vt;
    vt.vt = VT_INT;
    vt.intVal = m_ctrlDG.GetCol;
    CColumn  col  = cols.GetItem(vt);
    AfxMessageBox(col.GetText());
    }