嗨即時通訊嘗試存儲從數據網格中選定的項目的字符串,因爲它有一個文件路徑ID喜歡用於刪除。c#datagrid單元格提取
不知道我會以正確的方式去做。
我的柱子看起來像這樣
| ID | UserNumber |名字|姓氏|當前| imagePath |
.01 ... 454656 .........哈利..........波特.........嚮導.... ftp:// 192.168.1.8/Jellyfish.jpg
即時嘗試「選擇」在我的數據網格時,當我刪除我也從我的FTP服務器刪除。我需要存儲在imagePath coloum下的信息,以便我可以執行我的ftp刪除。
private void button2_Click(object sender, RoutedEventArgs e)
{
string imagePath = dataGrid1.SelectedItems.ToString();
Student selected = dataGrid1.SelectedItem as Stu;
if (selected == null)
MessageBox.Show("You must select a user");
else
{
if (MessageBoxResult.Yes == MessageBox.Show("Are you sure", "delete user",
MessageBoxButton.YesNo, MessageBoxImage.Warning))
{
FTPdelete(imagePath, "Administrator", "commando");
Class1.DeleteStudent(selected);
Window_Loaded(null, null);
}
}
}
private void FTPdelete(String imagePath, String inUsername, String inPassword)
{
var req = (FtpWebRequest)WebRequest.Create(imagePath);
req.Proxy = null;
req.Credentials = new NetworkCredential(inUsername, inPassword);
req.Method = WebRequestMethods.Ftp.DeleteFile;
req.GetResponse().Close();
}
}
}
錯誤我得到:
指數超出範圍。必須是非負數且小於集合的大小。參數名:索引
在這條線:
string imagePath = dataGrid1.SelectedItems[6].ToString();
香港專業教育學院還tryed
var imagePath = dataGrid1.SelectedItems[6].ToString();
沒有運氣:(思考我幾乎擁有了!!
還沒有得到錯誤:索引超出範圍。必須是非負數且小於集合的大小。 參數名稱:index – 2010-12-04 19:38:59