okay i have a listView with the detail option on and it has columns ...Actually the question is how can i get the selected index of the row clicked in the listView ???\
okay i have a listView with the detail option on and it has columns ...Actually the question is how can i get the selected index of the row clicked in the listView ???\
ListViews have ColumnClick Events. The second parameter of this event has a member of type ColumnHeader. This is the ColumnHeader that was clicked.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Okay so i found out how to get the selected item...But now my code is giving me alil problem ..which i have no idea about..
The exception thrown was "specific argument was out of the range of valid values.Parameter name : index"Code:private void bookingListView_SelectedIndexChanged(object sender, System.EventArgs e) { clearFields(); OleDbDataReader dbReader = null; string[] columns = new string[15]; try { conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; User Id =; Password=; Data Source=C:\professional\database" + @"\" + companys[companyComboBox.SelectedIndex] + @"\" + companys[companyComboBox.SelectedIndex] + @"_data.mdb" ); conn.Open(); OleDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM "+ client.GetKey(clientComboBox.SelectedIndex).ToString().Replace(' ','_'); dbReader = cmd.ExecuteReader(); //while( dbReader.Read() ) //{ MessageBox.Show(bookingListView.SelectedItems[0].Text/*bookingListView.Items[0].SubItems[0].Text*/,"" ,MessageBoxButtons.OK ); //} // conn.Close(); } catch( Exception error ) { MessageBox.Show("Exception: " + error.Message, "Error", MessageBoxButtons.OK ); } finally { if ( conn != null ) { conn.Close(); } } }
It still works fine after throwing the exception ....When i try doing this bookingListView1.SelectedItems[1].Text it throws the same exception ..
"I wish i could wish my wishs away"
"By indirections find directions out" -- William Shakespears
"Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"
Mizra -> love = Death...
RDB(Rocks yooo)..
http://www.cbeginnersunited.com
Are you ready for the Trix ???
bookingListView.SelectedItems[0].Text
There is not necessarily any SelectedItems. If you deselected the item, you will also get an SelectedIndexChanged event, but you will not have any SelectedItems.
Try
foreach( ListViewItem item in x.SelectedItems )
{
// action
}
OR
make sure you have selected items by querying SelectedItems.Count
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
thanks ...Actually i used another method and it worked ..
"I wish i could wish my wishs away"
"By indirections find directions out" -- William Shakespears
"Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"
Mizra -> love = Death...
RDB(Rocks yooo)..
http://www.cbeginnersunited.com
Are you ready for the Trix ???