Click here to Skip to main content
15,925,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Include guards vs. pragma Pin
peterchen19-Jan-08 9:39
peterchen19-Jan-08 9:39 
GeneralRe: Include guards vs. pragma Pin
Rajesh R Subramanian20-Jan-08 23:27
professionalRajesh R Subramanian20-Jan-08 23:27 
GeneralRe: Include guards vs. pragma Pin
peterchen21-Jan-08 10:03
peterchen21-Jan-08 10:03 
GeneralRe: Include guards vs. pragma Pin
Rajesh R Subramanian21-Jan-08 20:25
professionalRajesh R Subramanian21-Jan-08 20:25 
GeneralRe: Include guards vs. pragma [modified] Pin
Rajesh R Subramanian18-Jan-08 23:41
professionalRajesh R Subramanian18-Jan-08 23:41 
GeneralRe: Include guards vs. pragma Pin
73Zeppelin18-Jan-08 23:59
73Zeppelin18-Jan-08 23:59 
GeneralRe: Include guards vs. pragma Pin
CPallini19-Jan-08 4:43
mveCPallini19-Jan-08 4:43 
QuestionUsing ComboBox in MFC Grid Control Pin
Bhushan198018-Jan-08 15:44
Bhushan198018-Jan-08 15:44 
Hi Chris. First of all I am thankful to you for a wonderful grid control with entire source code that u have provided here on CP. Also want to thank for the revisions, additions, add-ons, database connectivity and other utilities related to the MFC Grid posted by various users on CP. I am one person making use of it in one of my applications where there is a requirement to display elements in 2-d/3-d data in a matrix form.
For 2-d arrays it is simple matrix-type table with rows and columns. For 3-d arrays, however, I have to make the cells combo-boxes and display the third dimension elements in the combo box. And I have done it. However, there is a need for my application to get hold of the combo-box inside the cells that is created at runtime. I want to set the contents of my application based on the element selected by the user in the combobox. In short, I want to perform all the operations related to a combo-box, that is created in every cell of the grid. And I want to set the cell text to the selection made by the user in the combo-box, which happens automatically ofcourse. However, after selection, I have to get the index selected inside the combo box and store it in a 2-d int array on the execution of the command button. And conversely I have to set the cell text from a 2-d int array holding the combobox from this array. I am using Visual Studio 2005 and my OS is Windows XP.

Here is the part of the code:

// Everything works fine in OnInitialUpdate() where I send data from 3-d int array to the grid...
// However I want to set the grid cell text to a combo item.
// I want to send the index selected into an int 2-d array when command button is executed.
// I want the grid cell text set by the combo box to be sent to a CString 2-d array when button is executed....
  
void CTest_GridView::OnInitialUpdate()
{
	CTest_GridDoc * pDoc = (CTest_GridDoc*)GetDocument();
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	int count = 0;
	for(int a = 0; a < 10; a++)
	{
		for(int b = 0; b < 10; b++)
		{
			for(int c = 0; c < 10; c++)
			{
				count++;
				pDoc->m_nDataArray[a][b][c] = count;  // array of int
			}
		}
	}
	this->m_Grid.SetRowCount(m_nRows);
	this->m_Grid.SetColumnCount(m_nCols);
	this->m_Grid.SetFixedRowCount(m_nFixedRows);
	this->m_Grid.SetFixedColumnCount(m_nFixedCols);
	CString sz;
	for (int x = 1; x < m_Grid.GetColumnCount(); x++)
	{
		sz.Format(_T("%d"), x);
		this->m_Grid.SetItemText(x, 0, sz);
		this->m_Grid.SetItemText(0, x, sz);
	}
	for (int i = 1; i < m_Grid.GetColumnCount(); i++)
	{
		for (int j = 1; j < m_Grid.GetRowCount(); j++)
		{
			m_Grid.SetCellType(i, j, RUNTIME_CLASS(CGridCellCombo));
			m_Grid.SetItemText(i, j, _T("My Number"));
			CString str;
			CStringArray options;
			for(int k = 0; k < 10; k++)
			{
				str.Format(_T("%d"), pDoc->m_nDataArray[i-1][j-1][k]);
				options.Add(str);
				str.Empty();
			}
			CGridCellCombo *pCell = (CGridCellCombo*) m_Grid.GetCell(i,j);
			pCell->SetOptions(options);
			pCell->SetStyle(CBS_DROPDOWN); //CBS_DROPDOWN, CBS_DROPDOWNLIST, CBS_SIMPLE
		}
	}

}
....
....
....
//////////////////////////////////////////////////////////////////////////////////////////
// CTest_GridView message handlers

void CTest_GridView::OnBnClickedButtonFix()
{
	// TODO: Add your control notification handler code here
	CTest_GridDoc * pDoc = (CTest_GridDoc*)GetDocument();
	CString sz;
	int num = -1;
	for (int i = 1; i < m_Grid.GetColumnCount(); i++)
	{
		for (int j = 1; j < m_Grid.GetRowCount(); j++)
		{
			CGridCellCombo * pCell = (CGridCellCombo*)m_Grid.GetCell(i, j);
			CWnd * pWnd = pCell->GetEditWnd();
			CComboBox * pCmb = (CComboBox*)pWnd;
			if(pCmb->GetCurSel() != CB_ERR)
				num = pCmb->GetCurSel();
			else
				num = 0;
			pDoc->m_nIndexArray[i-1][j-1] = num;
			pCmb->GetLBText(num, sz);
			pDoc->m_nComboText[i-1][j-1] = sz;
			sz.Empty();
		}
	}
}


I am using Visual Studio 2005 and the OS is Windows XP SP2. I have used a formview in a SDI application to display the grid and the button.

Thank you,
Bhushan.
GeneralRe: Using ComboBox in MFC Grid Control Pin
Hamid_RT18-Jan-08 18:58
Hamid_RT18-Jan-08 18:58 
GeneralRe: Using ComboBox in MFC Grid Control Pin
Bhushan198018-Jan-08 23:38
Bhushan198018-Jan-08 23:38 
GeneralRe: Using ComboBox in MFC Grid Control Pin
Rajesh R Subramanian19-Jan-08 2:44
professionalRajesh R Subramanian19-Jan-08 2:44 
QuestionRe: Using ComboBox in MFC Grid Control Pin
Bhushan198019-Jan-08 9:20
Bhushan198019-Jan-08 9:20 
GeneralRe: Using ComboBox in MFC Grid Control Pin
Rajesh R Subramanian21-Jan-08 20:28
professionalRajesh R Subramanian21-Jan-08 20:28 
GeneralDear all Pin
asmarani18-Jan-08 13:23
asmarani18-Jan-08 13:23 
QuestionRe: Dear all Pin
Mark Salsbery18-Jan-08 13:53
Mark Salsbery18-Jan-08 13:53 
GeneralRe: Dear all Pin
peterchen18-Jan-08 22:44
peterchen18-Jan-08 22:44 
GeneralRe: Dear all Pin
CPallini19-Jan-08 1:56
mveCPallini19-Jan-08 1:56 
GeneralRe: Dear all Pin
Mark Salsbery19-Jan-08 7:37
Mark Salsbery19-Jan-08 7:37 
GeneralRe: Dear all Pin
Paul Conrad19-Jan-08 11:55
professionalPaul Conrad19-Jan-08 11:55 
GeneralRe: Dear all Pin
Christian Graus18-Jan-08 15:09
protectorChristian Graus18-Jan-08 15:09 
GeneralRe: Dear all Pin
David Crow18-Jan-08 17:34
David Crow18-Jan-08 17:34 
GeneralRe: Dear all Pin
Mark Salsbery18-Jan-08 18:16
Mark Salsbery18-Jan-08 18:16 
GeneralRe: Dear all Pin
CPallini19-Jan-08 1:58
mveCPallini19-Jan-08 1:58 
GeneralRe: Dear all Pin
Rajesh R Subramanian19-Jan-08 2:44
professionalRajesh R Subramanian19-Jan-08 2:44 
QuestionRe: Dear all Pin
Hamid_RT18-Jan-08 19:00
Hamid_RT18-Jan-08 19:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.