English 中文(简体)
Use a MSHFlexGrid with non-database data and still define the shape
原标题:

I am trying to use the Microsoft Hierarchical FlexGrid (MSHFlexGrid) in a Visual C++ (VS 2005). I have the grid shown, and I can manually add data to the individual cells. However, according to online documentation I ve read, I should be able to show the hierarchical nature of the data (hence MSHFlexGrid instead of MSFlexGrid) by defining the SHAPE as the RecordSource. I can do that fine (by using the put_RecordSource method of the grid object), however I m at a loss as to how to add the actual data.

I ve read that the best way to do this is to use an ADO Data Control (ie ADODC) component and bind it as the DataSource for the Grid. You can then specify "provider=msdatashape;data provider=none;" as the provider of the DataControl and fill it with data. If I were doing SQL, I d specify my SELECT query as the RecordSource, then call Refresh() and let the control load the data.

However, my data is in custom objects. I know what needs to be displayed, I m just at a loss as to the best way to insert the data into the FlexGrid and still use the built in features of the control. I m open to any suggestions, but I need to keep the data local (ie no JET, Access, etc).

Here s some code:

In header:

....
// 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;
....

In 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;
}
问题回答

The sample talked about building an ADODB.Recordset and use it as the data source of ADODC. The code you give is building a SQL and use it as the data source of ADODC. I don t think you can replace an ADODB.Recordset with a string.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签