repeated data managment on listview control

  • Thread starter =?ISO-8859-1?Q?S=E9rgio_Almeida?=
  • Start date
?

=?ISO-8859-1?Q?S=E9rgio_Almeida?=

Greetings


I have a problem using listview control. Well, I belive that this is not
realy a problem, but it's consuming me precious time.

Here is the scenario (an example of my problem).

I have a SqlServer CE table named students that has 2 fields: students
name and grade.

I want to populate the a listview with all the students stored on my table.
(A simple select * from table sql statement). Simple so far... But
things get complicated because the name of the students are composed by
the first name and last name. So it can be the same names but regarding
different students! OK. In addition, the table has as primary key an
integer record named ID "auto incremented". This is what stays different
for all the records on table.

When I populate the listview, it displays on name column repeated data,
that in fact corresponds to different students.

My problem is when I have to edit or delete a record on database.

My listview has 2 columns - Name and Grade. When I populate the listview
I do something like this.

for(int i=0;i<theStudentsArray;i++)
{
StudentObj theStudentAux=theStudentsArray;
// each instance of StudentObj class has the
// properties Name, Grade and ID
string[] str=new string[2];

str[0]=theStudentAux.Name.ToString();
str[1]=theStudentAux.Grade.ToString();

ListViewItem lItem=new ListViewItem(str);

lViewStudents.Items.Add(lItem);
}

this is my code, but I'm not able to "put" the ID property (because I do
not want to show it on listview!) together with the ListViewItem. So,
when I want to delete or update a student with the name of Foo XPTO
(and, say, there are three Foo XPTOs on my list) I don't know what is
the one to update/delete on database! What I need is, when I select an
item of listview, to be able to get the database ID that corresponds to
that item. If ListViewItem have a Tag attribute the problem was solved.
But it does not contais the Tag attribute.

So what are your opinions for this problem?


Once far away time I've read an article regarthing this problem, but at
the time I did not pay much attention, and know I can't find it on the
web... :(

Can anyone give a hint?

TIA

Almeida
 
D

Daniel Moth

that item. If ListViewItem have a Tag attribute the problem was solved.
But it does not contais the Tag attribute.

So what are your opinions for this problem?

Inherit from ListViewItem and add your own (strongly typed) Tag property.

Cheers
Daniel


Sérgio Almeida said:
Greetings


I have a problem using listview control. Well, I belive that this is not
realy a problem, but it's consuming me precious time.

Here is the scenario (an example of my problem).

I have a SqlServer CE table named students that has 2 fields: students
name and grade.

I want to populate the a listview with all the students stored on my table.
(A simple select * from table sql statement). Simple so far... But
things get complicated because the name of the students are composed by
the first name and last name. So it can be the same names but regarding
different students! OK. In addition, the table has as primary key an
integer record named ID "auto incremented". This is what stays different
for all the records on table.

When I populate the listview, it displays on name column repeated data,
that in fact corresponds to different students.

My problem is when I have to edit or delete a record on database.

My listview has 2 columns - Name and Grade. When I populate the listview
I do something like this.

for(int i=0;i<theStudentsArray;i++)
{
StudentObj theStudentAux=theStudentsArray;
// each instance of StudentObj class has the
// properties Name, Grade and ID
string[] str=new string[2];

str[0]=theStudentAux.Name.ToString();
str[1]=theStudentAux.Grade.ToString();

ListViewItem lItem=new ListViewItem(str);

lViewStudents.Items.Add(lItem);
}

this is my code, but I'm not able to "put" the ID property (because I do
not want to show it on listview!) together with the ListViewItem. So,
when I want to delete or update a student with the name of Foo XPTO
(and, say, there are three Foo XPTOs on my list) I don't know what is
the one to update/delete on database! What I need is, when I select an
item of listview, to be able to get the database ID that corresponds to
that item. If ListViewItem have a Tag attribute the problem was solved.
But it does not contais the Tag attribute.

So what are your opinions for this problem?


Once far away time I've read an article regarthing this problem, but at
the time I did not pay much attention, and know I can't find it on the
web... :(

Can anyone give a hint?

TIA

Almeida
 
A

Alex Feinman [MVP]

Yup. Someting like this:
http://www.alexfeinman.com/download.asp?doc=ListViewDemo.zip

--
Alex Feinman
---
Visit http://www.opennetcf.org
Daniel Moth said:
that item. If ListViewItem have a Tag attribute the problem was solved.
But it does not contais the Tag attribute.

So what are your opinions for this problem?

Inherit from ListViewItem and add your own (strongly typed) Tag property.

Cheers
Daniel


Sérgio Almeida said:
Greetings


I have a problem using listview control. Well, I belive that this is not
realy a problem, but it's consuming me precious time.

Here is the scenario (an example of my problem).

I have a SqlServer CE table named students that has 2 fields: students
name and grade.

I want to populate the a listview with all the students stored on my table.
(A simple select * from table sql statement). Simple so far... But
things get complicated because the name of the students are composed by
the first name and last name. So it can be the same names but regarding
different students! OK. In addition, the table has as primary key an
integer record named ID "auto incremented". This is what stays different
for all the records on table.

When I populate the listview, it displays on name column repeated data,
that in fact corresponds to different students.

My problem is when I have to edit or delete a record on database.

My listview has 2 columns - Name and Grade. When I populate the listview
I do something like this.

for(int i=0;i<theStudentsArray;i++)
{
StudentObj theStudentAux=theStudentsArray;
// each instance of StudentObj class has the
// properties Name, Grade and ID
string[] str=new string[2];

str[0]=theStudentAux.Name.ToString();
str[1]=theStudentAux.Grade.ToString();

ListViewItem lItem=new ListViewItem(str);

lViewStudents.Items.Add(lItem);
}

this is my code, but I'm not able to "put" the ID property (because I do
not want to show it on listview!) together with the ListViewItem. So,
when I want to delete or update a student with the name of Foo XPTO
(and, say, there are three Foo XPTOs on my list) I don't know what is
the one to update/delete on database! What I need is, when I select an
item of listview, to be able to get the database ID that corresponds to
that item. If ListViewItem have a Tag attribute the problem was solved.
But it does not contais the Tag attribute.

So what are your opinions for this problem?


Once far away time I've read an article regarthing this problem, but at
the time I did not pay much attention, and know I can't find it on the
web... :(

Can anyone give a hint?

TIA

Almeida

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top