嗨即时通讯尝试存储从数据网格中选定的项目的字符串,因为它有一个文件路径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