|
You can use CListCtrl or derivated to display db data.
In search box you can test the user input with is_digit[^] and act accordingly (if is number then use ID to get data, or if is not number, use string to get the name and so on.
|
|
|
|
|
Thank you for always helping. I really appreciate the help
I have created a search function and now it's displaying in the CListCtrl and working the way I wanted.
I'll try to extend the functionality like if I select the result in the CListCtrl it will take me to another dialog that contains the details of the selected. If I have any doubt i'll post it here.
Thanks again 
|
|
|
|
|
You are welcome 
|
|
|
|
|
Hello I'm back again
How to get all the data present in a row displayed in the ListCtrl from the database and display those data in the next dialog?
For example:- There are name, age,dob..etc in a row.. when I select this row and press the select button.. It will take me to another where all this details will be display.
If you don't mind could you please give example.
Thanks.
|
|
|
|
|
Then you take all your list control data with CListCtrl::GetItemText[^] and you simply put them into next dialog, just like that:
CNextDlg dlg;
dlg.m_sName = m_ListCtrl.GetItemText(...);
dlg.m_sAge = m_ListCtrl.GetItemText(...);
dlg.m_sDOB = m_ListCtrl.GetItemText(...);
dlg.DoModal();
|
|
|
|
|
Thank you.
void CMyDlg::ResetListControl() {
m_ListControl.DeleteAllItems();
int iNbrOfColumns;
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
if (pHeader) {
iNbrOfColumns = pHeader->GetItemCount();
}
for (int i = iNbrOfColumns; i >= 0; i--) {
m_ListControl.DeleteColumn(i);
}
}
I particularly don't understand this line :
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
Could you please explain this line of code. Thanks 
|
|
|
|
|
I think that line should be:
CHeaderCtrl* pHeader = m_ListControl.GetHeaderCtrl();
See here[^].
However, that line retrieve first control item from m_ListCtrl object ... does working that line ? I didn't met such approach ...
|
|
|
|
|
Confidence that I have solved all strange errors here, I come back with some issue generated by a legacy C code for linux, code that I intend to use it in a MFC app in windows OS.
Ok. I have a simple code:
int nRespond = _open(device, 020);
UINT err = ::GetLastError();
where devide is const char* and has value C (or D:, or E: )
The nRespond is -1 and err has value 5, which is mean Access is denied . What could be the problem here ? I ran the test app as administrator mode (ran from VS2017 as admin mode).
|
|
|
|
|
The problem appears to be that you are expecting Linux code to work on Windows. The _open function opens a file - on unix systems you can open directories and devices as files, but not on Windows.
If you're lucky the code is actually expecting a normal file and you just passed in a device letter by mistake. Otherwise you will have to port the code, replacing the Linux system functions with code that does the same thing on Windows.
|
|
|
|
|
|
So I cannot open disk with this function ? ... this is the original code ... strange ...
|
|
|
|
|
_Flaviu wrote: this is the original code From where?
|
|
|
|
|
I get this code from a plain C code which has built for Linux:
int nRespond = _open(device, 020);
|
|
|
|
|
You cannot run Linux code on Windows without adjusting it for the differences. Windows does not let you address raw devices in the same way that Linux does. And in fact doing so is very dangerous as you could destroy your entire system.
|
|
|
|
|
And is any other method to open a device rather than _open in Windows ? I think I have to made some changes into Linux code to run on Windows ...
modified 4-Sep-19 7:31am.
|
|
|
|
|
I gave you a link in my first message above which shows details of how to address devices in Windows. However, the real question is, what exactly are you trying to do?
|
|
|
|
|
Your flags (020) are linux flags not windows try ( _O_WRONLY | _O_CREAT ) or some normal windows flags
_open, _wopen | Microsoft Docs[^]
I would add even in linux the code really should be written as flags not a value like that for this exact reason.
In vino veritas
modified 2-Sep-19 4:33am.
|
|
|
|
|
I have tried this:
int nRespond = _open(device, _O_WRONLY | _O_CREAT);
UINT e = ::GetLastError();
with the same result (error 5). Strange ....
|
|
|
|
|
I also tried this:
#include <io.h>
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
_open("D:", 0x02 | 0x04);
UINT e = ::GetLastError();
cout << e;
}
from cmd line as administrator rights … the same result: 5 (access is denied).
|
|
|
|
|
Big Errors
You can't open "D:" that isn't a file ... its not linux you don't mount drives
Try
int nRespond = _open("D:\\somefilename.txt", _O_WRONLY | _O_CREAT);
UINT e = ::GetLastError();
I am sure it will open
In vino veritas
|
|
|
|
|
Agree. Is there any windows methods to open a disk and get the handle ? Because this nResponse it is used further as a handle ...
|
|
|
|
|
|
Good idea. I have used CreateFileA, and I get rid of that "access denied". But there a thing that I had afraid: the original code, with _open returned int, and CreateFileA return HANDLE ... casting HANDLE to int is OK ? I guess not ...
|
|
|
|
|
How are you going to use the handle returned from _open ?
|
|
|
|
|
Windows has GetLastError you notice CreateFile Simply returns invalid handle for an error if you get that then you call GetLastError
GetLastError function (errhandlingapi.h) | Microsoft Docs[^]
That is the equivalent of your original int it's just a non zero number identifying the error, 0 always equals no error.
In vino veritas
|
|
|
|