using listview control in smart device
-
hi everybody, I am trying to create a multicolumn listview knowing that it is not possible to do with a listbox I have 2 questions: the first is how can i display the header of the columns? the second is how can i get data from a data base .sdf and display it on the colomuns of my listview? Thank you in advance
-
hi everybody, I am trying to create a multicolumn listview knowing that it is not possible to do with a listbox I have 2 questions: the first is how can i display the header of the columns? the second is how can i get data from a data base .sdf and display it on the colomuns of my listview? Thank you in advance
bacem smari wrote:
the first is how can i display the header of the columns?
just set the ListView's View to details.
bacem smari wrote:
the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?
Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.
-
bacem smari wrote:
the first is how can i display the header of the columns?
just set the ListView's View to details.
bacem smari wrote:
the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?
Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.
hi, thank you but i am trying to fill the listview with the result of a querry. Can you help me?
-
bacem smari wrote:
the first is how can i display the header of the columns?
just set the ListView's View to details.
bacem smari wrote:
the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?
Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.
Hi , This is the code that i am using. It indicates no errors but my listview isn't filled with the result of the querry. Can you help me.
private void button1_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command = sqlceconn.CreateCommand();
command.CommandText = "SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt";
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
txt.Value = textBox1.Text;
command.Parameters.Add(txt);
DataSet ds = new DataSet();
adapter.Fill(ds);
string[] str = new string[ds.Tables[0].Columns.Count];
foreach (DataRow dr in ds.Tables[0].Rows)
{
for (int col = 0; col <= ds.Tables[0].Columns.Count-1; col++)
{
//filling the array of string
str[col] = dr[col].ToString();
}
ListViewItem ii;
ii = new ListViewItem(str);
this.listView1.Items.Add(ii);
}}
-
Hi , This is the code that i am using. It indicates no errors but my listview isn't filled with the result of the querry. Can you help me.
private void button1_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command = sqlceconn.CreateCommand();
command.CommandText = "SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt";
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
txt.Value = textBox1.Text;
command.Parameters.Add(txt);
DataSet ds = new DataSet();
adapter.Fill(ds);
string[] str = new string[ds.Tables[0].Columns.Count];
foreach (DataRow dr in ds.Tables[0].Rows)
{
for (int col = 0; col <= ds.Tables[0].Columns.Count-1; col++)
{
//filling the array of string
str[col] = dr[col].ToString();
}
ListViewItem ii;
ii = new ListViewItem(str);
this.listView1.Items.Add(ii);
}}
Well, first, glad to see that you figured out how to write the SELECT statement properly...or at least more so. But the problem is still with the SELECT...or at least that's one problem. You said,
WHERE ID Like @txt
. That will only return values where ID is equal to @txt. You need to add back in the '%'. Try:txt.Value = "%" + textBox1.Text + "%";
If that doesn't work, then you would need to check the db. Also, you do realize that you're selecting exactly 3 columns, right? You don't need to ask the table how many columns there are because there will always be three.
-
Well, first, glad to see that you figured out how to write the SELECT statement properly...or at least more so. But the problem is still with the SELECT...or at least that's one problem. You said,
WHERE ID Like @txt
. That will only return values where ID is equal to @txt. You need to add back in the '%'. Try:txt.Value = "%" + textBox1.Text + "%";
If that doesn't work, then you would need to check the db. Also, you do realize that you're selecting exactly 3 columns, right? You don't need to ask the table how many columns there are because there will always be three.
thank you for the information. I think that you didn't understand my code very well. it's the datatable that i am getting the columns form. every column must appear on the listview. Can you help me? thank you.
-
thank you for the information. I think that you didn't understand my code very well. it's the datatable that i am getting the columns form. every column must appear on the listview. Can you help me? thank you.
All that I was saying was that your SELECT statement only specified 3 columns,
SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt
If there are more columns and you want them all, then, it should just be
SELECT * FROM ...
-
All that I was saying was that your SELECT statement only specified 3 columns,
SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt
If there are more columns and you want them all, then, it should just be
SELECT * FROM ...
thank you. I know the command. I just want these 3 columns.