我试图使用Microsoft分层FlexGrid(MSHFlexGrid中)在Visual C ++(VS 2005)。我有所示的网格,我可以数据手动添加到个体的细胞。然而,根据网上我读过href="http://support.microsoft.com/kb/196029" rel="nofollow noreferrer">文件,我应该能够表现出层次性的数据的(因此MSHFlexGrid的代替MSFlexGrid控件)通过定义形状的记录源。我能做到这一点罚款(通过使用网格物体的put_RecordSource方法),但我在一个不知如何添加的实际数据。

我读过,要做到这一点最好的办法是使用一个ADO数据控件(即ADODC)成分并结合其作为数据源的网格。然后,您可以指定“提供= msdatashape;数据提供商=无;”作为DataControl上的供应商,并用数据填充它。如果我做的SQL,我指定我的SELECT查询作为记录源,然后调用刷新(),并让控制加载数据。

然而,我的数据是在自定义对象。我知道需要显示的内容,我只是在亏损为插入数据到FlexGrid的,仍然使用内置的控制功能的最佳途径。我愿意接受任何建议,但我需要保持数据的本地(即没有JET,访问等)。

下面是一些代码:

在报头:

....
// Variable to control the Flex Grid component
CMshflexgrid1 m_grid;  //generated by wizard from the MSHFlexGrid component

// to control the data source hierarchical information
CAdodc1 m_adodc1;
....

在CPP:

....
BOOL MyDialogClass::OnInitDialog()
{
  CDialog::OnInitDialog();

  m_grid.Clear();

  CString strCn = "provider=msdatashape;data provider=none;"; 
  m_adodc1.put_ConnectionString(strCn);

  CString BackupOfRecordSource = "";
  BackupOfRecordSource = m_adodc1.get_RecordSource();

  //CString strShape = "SHAPE APPEND new adInteger As PID, New adVarChar(10) As StudentName, ((SHAPE APPEND new adInteger As ChID, New adVarChar(10) As Course, ((SHAPE APPEND new adInteger As GrndChID, New adBSTR As Description) RELATE  ChID TO GrndChID) As GrandChild) RELATE PID TO ChID) AS Child";
  CString strShape = "SHAPE APPEND new adInteger As PID, New adVarChar(10) As StudentName";
  m_adodc1.put_RecordSource(strShape);
  m_adodc1.Refresh();
  m_grid.Refresh();

  BackupOfRecordSource = m_adodc1.get_RecordSource();  //returns the strShape that I just put in

  //ADD RECORDS HERE!  HOW?

  return TRUE;
}

没有正确的解决方案

其他提示

在样品谈到构建ADODB.Recordset并使用它作为ADODC的数据源。你给的代码是建立一个SQL,并把它作为ADODC的数据源。我不认为你可以替换字符串的ADODB.Recordset。

scroll top