|
Hi
I need to know the method to fill the ListView with my database contents. I tried with the help of the Dataset, but could not find any solution to it.
I am not able to populate the list view with my dataset contents.
Please send me any sample code to solve this problem.
Kindly do me a favour by helping me to find the solution to this.
Thank you
-- modified at 4:36 Tuesday 5th December, 2006
Kind Regards
Sandy
|
|
|
|
|
Here is a code snippet that i have used to update the listview from a DataSet. This snippet goes the each row in the dataset (in my case myDataSet) and Creates a ListViewItem to add to your ListView Control (in my case myListView1).
for each (DataRow^ r in myDataSet->Tables[0]->Rows)
{
ListViewItem^ lvindex = gcnew ListViewItem(r[0]->ToString());
ListViewItem::ListViewSubItem^ sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[1]->ToString());
myListView1->SubItems->Add(sublvindex);
sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[2]->ToString());
myListView1->SubItems->Add(sublvindex);
myListView1->Items->Add(lvindex);
}
hope this helps.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I am really greatfull to you for the support replay...
But i guess the code is not for VC++.Net, I need to it in managed C++, where i am not able to use the keywords like "for Each" & Table[0]->. I am geeting error for this code.
Can you kindly tell me if there is a problem with my code or else i need alter the code provided by you...
Please do me a favour by giving me this piece of Info.
Thanks a lot
Kind Regards
Sandy
|
|
|
|
|
Yes, this snippet is for Managed C++. Please post your code and copy the errors your getting from the error window and i'll see if i can fix it.
Thanks
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi,
Yeah kindly find the list of errors below which are fired when i use this piece of code.
This is my code :
private: System::Void Form1_Load(System::Object * sender, System::EventArgs e)
{
System::String * SqlStr;
ListView * listView1 = new ListView();
try
{
SqlStr = "Select IC, Part_Code, PART_NUMBER, PART_NAME from vdcsssp_PARTS_mst" ;
SqlCommand* objCmd = new SqlCommand();
SqlDataAdapter* objDA = new SqlDataAdapter();
DataSet* objDS = new DataSet();
SqlConnection* objCon = new SqlConnection();
objCon->ConnectionString = "User ID=sa;pwd=qil2004;Data Source=qipl-server;Initial Catalog=Qvdcsssp";
if(objCon->get_ConnectionString() != "")
{
objCon->Open();
objCmd->CommandText = SqlStr;
objCmd->Connection = objCon;
objDA->SelectCommand = objCmd;
objDA->Fill(objDS);
}
else
MessageBox::Show("Error connection Failed");
return;
for each (DataRow* r in objDS->Tables[0]->Rows)
{
//Create a listView Item and add the first column of the dataset to it
ListViewItem* lvindex = gcnew ListViewItem(r[0]->ToString());
//Create a subitem and add the seconed column to it
ListViewItem::ListViewSubItem* sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[1]->ToString());
//Add the 1st subitem to the listview item
listView1->SubItems->Add(sublvindex);
//Create the seconed ListView SubItem and add the third column of the Dataset to it.
sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[2]->ToString());
//Add the 2nd subitem to the listview item
listView1->SubItems->Add(sublvindex);
//Add the entire ListViewItem to the next available row in myListView
listView1->Items->Add(lvindex);
}
}
catch(Exception* ex)
{
MessageBox::Show(ex->Message);
}
-----------------------------------------------------------------------------
This is my errors:
e:\Sandeep\VC++ .Net\Test1\Form1.h(376) : error C2061: syntax error : identifier 'each'
e:\Sandeep\VC++ .Net\Test1\Form1.h(377) : error C2143: syntax error : missing ';' before '{'
e:\Sandeep\VC++ .Net\Test1\Form1.h(379) : error C2065: 'gcnew' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(379) : error C2146: syntax error : missing ';' before identifier 'ListViewItem'
e:\Sandeep\VC++ .Net\Test1\Form1.h(379) : error C2065: 'r' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(379) : error C2227: left of '->ToString' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(381) : error C3861: 'gcnew': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(381) : error C2143: syntax error : missing ';' before 'System::Windows::Forms::ListViewItem::ListViewSubItem'
e:\Sandeep\VC++ .Net\Test1\Form1.h(381) : error C2227: left of '->ToString' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(381) : error C3861: 'r': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(383) : error C2039: 'SubItems' : is not a member of 'System::Windows::Forms::ListView'
stdafx.cpp(0) : see declaration of 'System::Windows::Forms::ListView'
e:\Sandeep\VC++ .Net\Test1\Form1.h(383) : error C2227: left of '->Add' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(385) : error C2143: syntax error : missing ';' before 'System::Windows::Forms::ListViewItem::ListViewSubItem'
e:\Sandeep\VC++ .Net\Test1\Form1.h(385) : error C3861: 'gcnew': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(385) : error C2227: left of '->ToString' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(385) : error C3861: 'r': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(387) : error C2039: 'SubItems' : is not a member of 'System::Windows::Forms::ListView'
stdafx.cpp(0) : see declaration of 'System::Windows::Forms::ListView'
e:\Sandeep\VC++ .Net\Test1\Form1.h(387) : error C2227: left of '->Add' must point to class/struct/union
Kind Regards
Sandy
|
|
|
|
|
 I think (don't quote me on it) the problem was that you were trying to create a control using a pointer (*) and that is why alot of the error's came up. The snippet below compiled fine for me give it a try and let me know how it works for you. If you have anymore problems you can also email me djcarter2326@aim.com. I'm more used to using C# but i am teaching myself Managed C++.
System::String ^ SqlStr;
ListView ^ listView1 = gcnew ListView();
try
{
SqlStr = "Select IC, Part_Code, PART_NUMBER, PART_NAME from vdcsssp_PARTS_mst" ;
SqlCommand^ objCmd = gcnew SqlCommand();
SqlDataAdapter^ objDA = gcnew SqlDataAdapter();
DataSet^ objDS = gcnew DataSet();
SqlConnection^ objCon = gcnew SqlConnection();
objCon->ConnectionString = "User ID=sa;pwd=qil2004;Data Source=qipl-server;Initial Catalog=Qvdcsssp";
if(objCon->ConnectionString != "")
{
objCon->Open();
objCmd->CommandText = SqlStr;
objCmd->Connection = objCon;
objDA->SelectCommand = objCmd;
objDA->Fill(objDS);
}
else
MessageBox::Show("Error connection Failed");
return;
for each (DataRow^ r in objDS->Tables[0]->Rows)
{
ListViewItem^ lvindex = gcnew ListViewItem(r[0]->ToString());
ListViewItem::ListViewSubItem^ sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[1]->ToString());
lvindex->SubItems->Add(sublvindex);
sublvindex = gcnew ListViewItem::ListViewSubItem(lvindex,r[2]->ToString());
lvindex->SubItems->Add(sublvindex);
listView1->Items->Add(lvindex);
}
}
catch(Exception^ ex)
{
MessageBox::Show(ex->Message);
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi
I dont know if i can use the char '^' works here i am getting errors on using this...
The errors are...
e:\Sandeep\VC++ .Net\Test1\Form1.h(386) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(386) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(387) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(387) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(390) : error C2065: 'SqlStr' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(391) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(391) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(392) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(392) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(393) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(393) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(394) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(394) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(399) : error C3861: 'SqlStr': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(407) : error C2061: syntax error : identifier 'each'
e:\Sandeep\VC++ .Net\Test1\Form1.h(408) : error C2143: syntax error : missing ';' before '{'
e:\Sandeep\VC++ .Net\Test1\Form1.h(410) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(410) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(412) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(412) : error C2143: syntax error : missing ';' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(414) : error C2065: 'lvindex' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(414) : error C2227: left of '->SubItems' must point to class/struct/union
type is ''unknown-type''
e:\Sandeep\VC++ .Net\Test1\Form1.h(414) : error C2227: left of '->Add' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(414) : error C2065: 'sublvindex' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C2065: 'gcnew' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C2143: syntax error : missing ';' before 'System::Windows::Forms::ListViewItem::ListViewSubItem'
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C3861: 'sublvindex': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C2065: 'r' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C2227: left of '->ToString' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(416) : error C3861: 'lvindex': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(418) : error C2227: left of '->SubItems' must point to class/struct/union
type is ''unknown-type''
e:\Sandeep\VC++ .Net\Test1\Form1.h(418) : error C2227: left of '->Add' must point to class/struct/union
e:\Sandeep\VC++ .Net\Test1\Form1.h(418) : error C3861: 'lvindex': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(418) : error C3861: 'sublvindex': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(420) : error C3861: 'lvindex': identifier not found, even with argument-dependent lookup
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C3149: 'System::Exception' : illegal use of managed type 'System::Exception'; did you forget a '*'?
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2143: syntax error : missing ')' before '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2725: 'System::Exception' : unable to throw or catch a __gc type object by value or reference
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2316: 'System::Exception' : cannot be caught as the destructor and/or copy constructor are inaccessible
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2319: 'catch' must be followed by a compound statement. Missing '{'
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2059: syntax error : '^'
e:\Sandeep\VC++ .Net\Test1\Form1.h(423) : error C2059: syntax error : ')'
e:\Sandeep\VC++ .Net\Test1\Form1.h(424) : error C2143: syntax error : missing ';' before '{'
e:\Sandeep\VC++ .Net\Test1\Form1.h(425) : error C2065: 'ex' : undeclared identifier
e:\Sandeep\VC++ .Net\Test1\Form1.h(425) : error C2227: left of '->Message' must point to
Kind Regards
Sandy
|
|
|
|
|
How can i know the WDFDEVICE details of any device.
WDFDEVICE is A handle to a framework device object
|
|
|
|
|
Hi all,
How do I export functions from a .c externsion file say, app.c file( there is an app.h file too)to a test.c file??
All the file extensions are .c and iam using gcc to compile. Iam doing C not C++.
I do in test.h file the following:
#ifndef _TEST_H<br />
#define _TEST_H<br />
<br />
extern void func1(void);<br />
<br />
#endif /* _TEST_H */
but the compiler returns with an error:
test.h:4: warning: function declaration isn't a prototype
Can anyone help me with whats happening that will help me understand much better on exporting functions.
Thanks in advance.
-- modified at 2:35 Monday 4th December, 2006
|
|
|
|
|
|
ROTFL !!!
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
There's nothing more annoying than when someone asks clueless questions, and when you try to help them anyhow, they don't answer you, and delete all their posts.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I feel your pain and have seen your effort to help even the clueless. Many of them want to obtain knowledge and information without paying the price of learning something. If they don't understand where they need help, all of our assistance is lost in their dark clueless void of educational enlightenment. However, there is always joy when you actually see your assistance light a candle.
Geo
|
|
|
|
|
This would take me about 5 minutes to write, about the same amount of time I'll spend on this post.
Here's why I didn't write the code for you.
There's about a 3% chance that your teacher won't notice that you've passed in production quality code, but aren't smart enough to post your homework questions in the right forum ( or to just post them once). But, some people are lucky. If you were to pass your course, there's a slim chance that I'll find myself with a lazy and clueless co-worker.
My plea to you - if you can't be bothered learning basic C++, change courses, or just apply at McDonalds and be done with it.
If, on the other hand, you try to do your own homework, and ask specific questions if you get stuck, I'll be the first to try to help.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
CHELA FE wrote: sir, can you give me some technique in c++ and how to make a code or programm?or give me some examples
This is a very vague question. What books do you have ? What are your course materials ? What level of school is this ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If you're doing a course that has no course materials, I hope you didn't pay for it.
You need to buy a book, like 'teach yourself C++ in 24 hours' or something. Until you get to a point of basic understanding, you're going to have trouble finding help online. Stuff like how structs work, and iostreams, are widely documented on the web, if you're unable to use google to solve the question you asked, you're probably not at a level of being able to understand the sort of brief answers you will get on these forums.
Have you written any code at all ? What do you know how to write ? I'm trying to establish what I could tell you, and that you'd be able to follow.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello everybody,
I am a newbie to C++ programming and I need to do some hex addition with VC++ and then output the result as ASCII.
Here is my problem:
hex1(5A 30 35 30 30) which is equal to decimal(387355848752), I want to add hex(100) to hex1 which is hex2(5A 30 35 31 30) equal to decimal(387355849008). This is exactly equal to adding 256 to the first decimal.
I know unsigned int data type can only support 4294967295 which is still not enough for my case, and I would like to know how to convert these hex to ASCII with C++?
Your help is very much appreciated, thank you.
|
|
|
|
|
If this is a C++ question and not a C++/CLI question then you are in the wrong forum.
<br />
long long h1 = 0x5A30353030LL;<br />
long long h2 = 0x100LL;<br />
<br />
_tprintf_s(_T("%I64X\n"), h1 + h2);<br />
-- modified at 13:03 Saturday 2nd December, 2006
|
|
|
|
|
Thank you very much!
It works fine and I was in such hurry and I overlooked (Managed), and I should have posted on the VC++/MFC board? Sorry for my mistake.
Besides, how can I convert the resulting hex to ASCII string? Is there a function _tprintf_s(_T("%s\n"), h1+h2); ? I tried but it does not work.
-- modified at 13:35 Saturday 2nd December, 2006
|
|
|
|
|
what are the API's to detect the USB Device descriptor
Shiva....
|
|
|
|
|
|
I think the forum name must be changed. People see "C++/CLI" and think they can post questions on plain C++ or CLI, cause they are not aware of "C++/CLI". It's really confusing for beginners. I think the forum should be named "Managed C++", and Visual C++ forum should be named "C++ & Visual C++"
Although the discussion forum is (Managed) C++/CLI, from the drop down menu of "Message Boards" it is written "C++/CLI", and that's what is confusing people.
|
|
|
|
|
I absolutely agree with this idea! The name must clearly represent the topic, otherwise the "you're on a wrong forum" nightmare will continue. :->
|
|
|
|
|
It's funny, because you're posting in the wrong forum. There is a 'suggestions' forum.
I tend to agree in principle, but the fact is, I can't think of anything we can name this forum that will stop people from just seeing 'C++' and filtering out the bit they don't understand.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: It's funny, because you're posting in the wrong forum.
Great way to start my day! Thanks
led mike
|
|
|
|