Home > Software engineering >  Help: MFC ListCtrl display data in disorder problem?
Help: MFC ListCtrl display data in disorder problem?

Time:09-23

, good, I am a rookie, doing a database curriculum design, curriculum design requirements using vc and SQL server to write a book management procedures, at present has achieved the odbc connection, MFC on the program, but the list control ListCtrl how to adjust all adjust bad, select use the chart shows, like the image below the whole is mess:

However, in the inside of the database data is like this:

I tried to put into Listctrl report form, but in that case directly show anything not to come out, the whole is empty, don't know why,
I want listctrl display like the inside of the database, line by line tuples each show this way,

In addition, every time after I click the query, input the data of does not exist in a database, and then it will be prompted to I didn't find the book you are looking for "information", but the next program inside all button (query, modify, etc.) may not be able to use, also will be prompted to "attempt to scroll past end or before beginning of data", don't know why, I post code of the query button up, problems may be in code, the great god can also help if I have time I can look at?
All new integral is not much, as far as possible, please! Curriculum design in these two days, very urgent,
The following is the query button code:
 void CTSGLView: : OnButton2 () 
{//TODO: Add your the control notification handler code here
Csearch Dlg.
The UpdateData (true);
If (Dlg) DoModal ()==IDOK)
{m_pSet - & gt; Edit ();
Dlg. M_1. TrimLeft ();//the string space in front of the trim off
Dlg. M_2. TrimLeft ();//the string space in front of the trim off
Dlg. M_3. TrimLeft ();//the string space in front of the trim off
If (Dlg) m_1) IsEmpty () & amp; & Dlg. M_2. IsEmpty () & amp; & Dlg. M_3. IsEmpty ())
{MessageBox (" to query conditions can't be empty! ");
return;
}
If (m_pSet - & gt; IsOpen ())
M_pSet - & gt; Close ();//if the recordset is opened, the first shut down
if(! (Dlg. M_1. IsEmpty ()) & amp; & ! (Dlg. M_2. IsEmpty ()) & amp; & (Dlg. M_3. IsEmpty ()))
{m_pSet - & gt; M_strFilter. The Format (" book number='% s' AND the title=' % s' AND the author's name='% s' ", Dlg, m_1, Dlg) m_2, Dlg, m_3);
M_pSet - & gt; The title m_strSort="book number ASC, ASC, the author of the ASC"; }
The else
{m_pSet - & gt; M_strFilter. The Format (" id='% s' books OR book title=' % s' OR author name='% s' ", Dlg, m_1, Dlg) m_2, Dlg, m_3);
//m_strFilter set filters
a recordM_pSet - & gt; The title m_strSort="book number ASC, ASC, the author of the ASC";
Order of the record of the//m_strSort Settings. The records in descending order of number}
M_pSet - & gt; The Open ();
//Open the recordset. Open function in constructing a SELECT statement,
//will put m_strFilter and m_strSort content in the WHERE clause of a SELECT statement and ORDER BY clause in the
if (! M_pSet - & gt; IsEOF ())
{m_pSet - & gt; Requery ();//if you open recordset recorded
The UpdateData (false);
OnButton1 ();
OnInitialUpdate (); }
The else
MessageBox (" didn't find the book you are looking for the information! ");
}}
}

CodePudding user response:

Reporting mode

 
DWORD style=C_List. GetExtendedStyle ();
M_List. SetExtendedStyle (style | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//the following to insert a few column column headings
M_List. InsertColumn (1, _T (" 1 "), LVCFMT_LEFT, 40, 1);
M_List. InsertColumn (2, _T (" column 2 "), LVCFMT_LEFT, 40, 2);
M_List. InsertColumn (3, _T (" column "), LVCFMT_LEFT, 80, 3);
M_List. InsertColumn (4, _T (column 4), LVCFMT_LEFT, 80, 4);

When inserting data:
M_List. DeleteAllItems ();//to empty the list box
for(int j=0; j<=nCount; J++)
{
M_List. InsertItem (j, _T (" c "));//insert a row first, one of the characters can be arbitrary, can also be null
STR. The Format (_T (" % d "), j);
M_List. SetItemText (j, 0, STR);//set the first column data
STR. The Format (_T (" % d "), j + 1);
M_List. SetItemText (j, 1, STR);//set the second column data, so you can set the other columns of data
}

CodePudding user response:

reference 1st floor zgl7903 response:

report-mode
 
DWORD style=C_List. GetExtendedStyle ();
M_List. SetExtendedStyle (style | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//the following to insert a few column column headings
M_List. InsertColumn (1, _T (" 1 "), LVCFMT_LEFT, 40, 1);
M_List. InsertColumn (2, _T (" column 2 "), LVCFMT_LEFT, 40, 2);
M_List. InsertColumn (3, _T (" column "), LVCFMT_LEFT, 80, 3);
M_List. InsertColumn (4, _T (column 4), LVCFMT_LEFT, 80, 4);

When inserting data:
M_List. DeleteAllItems ();//to empty the list box
for(int j=0; j<=nCount; J++)
{
M_List. InsertItem (j, _T (" c "));//insert a row first, one of the characters can be arbitrary, can also be null
STR. The Format (_T (" % d "), j);
M_List. SetItemText (j, 0, STR);//set the first column data
STR. The Format (_T (" % d "), j + 1);
M_List. SetItemText (j, 1, STR);//set the second column data, so you can set the other columns of data
}


Thank you, I'm a little don't quite understand, I have been inside the database, the data I want to ask directly set your template is ok

CodePudding user response:

You try to know,

As well as a support database control can refer to the the DataGrid

CodePudding user response:

Need binding database and the data is modified, suggest a DataGrid with data component directly, because ListCtrl to edit, need additional custom many things, and the data component has help you to achieve the function of editing and data update,

CodePudding user response:

Should have your Listctrl initialization code is coming
  • Related