Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two listview boxes and their respective data is being stored in the database. What code I write in code event SelectIndexChanged. Ex: str = "select judgement from casetab WHERE partyname='" + listView1.Items + "'";

What should i change this "listView1.Items" to???

Please advise. Thank you, Nirmal
Posted
Comments
Richard C Bishop 17-May-13 14:41pm    
I would use:

listView1.SelectedValue.ToString()
ZurdoDev 17-May-13 14:42pm    
You should post as solution.
[no name] 17-May-13 14:42pm    
Hi Rich,
Sorry, I am not getting Selected Value in the Intellisense
Richard C Bishop 17-May-13 14:46pm    
Post the code you have for the ListView. ListView has a SelectedValue I assure you.
[no name] 17-May-13 14:45pm    
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
listView2.Items.Clear();


OleDbConnection cs = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\lms\ssc.mdb;");
string str;
//OleDbCommand cmd = new OleDbCommand("SELECT * FROM casetab", cs);


listView2.View = View.Details;
// listView2.GridLines = true;
//listView2.BackColor = Color.Aqua;
// listView2.ForeColor = Color.Blue;


cs.Open();
str = "select judgement from casetab WHERE partyname='" + listView1.SelectedValue.ToString()+ "'";

OleDbCommand cmd;
cmd = new OleDbCommand(str, cs);


OleDbDataAdapter da;
da = new OleDbDataAdapter(cmd);

DataSet ds;


ds = new DataSet();
da.Fill(ds, "casetab");
cs.Close();

DataTable dt;
dt = ds.Tables["casetab"];


int i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
listView2.Items.Add(dt.Rows[i].ItemArray[0].ToString());
// listView2.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());

}
}

1 solution

Since this is a Windows Forms application you can use:
listView1.SelectedItems.ToString()

SAK might take issue with this, but I am not exactly sure how to use ENUMS yet and definitely am not capable of telling others to.
 
Share this answer
 
Comments
[no name] 17-May-13 14:56pm    
Hmm.. Okie. If you could atleast let me know how to increase the height of the text displayed in the listview. I have a column called judgement and text in it is huge. I am able to only view only one line in the listview.

Would you be able to assist.

--
NG
Richard C Bishop 17-May-13 15:03pm    
Add a try catch to your application and debug it in order to find out where it stops working. As far as formating the text, I am not sure on that. Research it, as that is what I would have to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900