Hi Sir, I'm here again hopping for your help. Sir, how can i delete multiple row in list view with mysql? I have already a code for deleting but it work only in one row and when i check and select more than one row it doesn't. How can i do that sir. Here is my code for delete.
private void btnPdel_Click(object sender, EventArgs e)
{
foreach(int t in petlist.CheckedIndices)
{
string s = petlist.Items[t].Text.ToString();
if (petlist.SelectedItems.Count > 0 )
{
ListViewItem lv = petlist.SelectedItems[0];
string cid = lv.SubItems[6].Text;
string petdel = "Delete from petreg where petId = '" + s + "' and clientId ='" + cid + "'";
MySqlConnection connect = new MySqlConnection(conn);
MySqlCommand cmd = new MySqlCommand(petdel, connect);
connect.Open();
int execute = 0;
execute = cmd.ExecuteNonQuery();
connect.Close();
if (execute.Equals(1))
{
petload();
MessageBox.Show("Data was succesfully deleted", "Mysql says...", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The data is protected", "Error message", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
}
}
Thanks Sir.
Loading
Jignesh TrivediPosted Aug 2, 2012, 12:16 AM
try following code.......
// using this you can only find checked item list
ListView.CheckedListViewItemCollection checkedItems = listView1.CheckedItems;
foreach (ListViewItem item in checkedItems)
{
// This will fill the list with ListViewItems that are checked
// In item.Text you can find name list item
//write your delete logic
}
please refer....
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.checkboxes.aspx
hope this will help you.
vergel aranasPosted Aug 1, 2012, 4:09 PM
Jignesh TrivediPosted Jul 11, 2012, 11:32 PM
I assume that you use Checkbox list control.
try
for (var i = 0; i <= (checkedListBox1.Items.Count - 1); i++)
{
if (checkedListBox1.GetItemChecked(i))
{
// Here you only find item if it is selected.
// write your delete code.
Console.WriteLine(checkedListBox1.Items[i].ToString());
}
}
hope this will help you.
vergel aranasPosted Jul 11, 2012, 1:25 PM
Jignesh TrivediPosted Jul 11, 2012, 12:08 AM
Can please provide information about, which control are you using in your application and also technology like winform or web?
thx.