Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3459776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:08:55+00:00 2026-05-18T10:08:55+00:00

Hey im trying to store a string from a selected item in a datagrid

  • 0

Hey im trying to store a string from a selected item in a datagrid as it has a filepath id like to use to delete.

Not sure im going about it the right way.

my colums look like this

| ID | UserNumber | FirstName | LastName | Current | imagePath |

..01…454656………Harry……….Potter………Wizard….ftp://192.168.1.8/Jellyfish.jpg

im trying to “on selection” in my datagrid when i delete i also delete from my ftp server. I need the info stored under imagePath coloum so I can then do my ftp delete.

    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();
}

}

}

the error i get:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

on this line:

string imagePath = dataGrid1.SelectedItems[6].ToString();

Ive also tryed

var imagePath = dataGrid1.SelectedItems[6].ToString();

No luck 🙁 Thought I almost had it!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:08:56+00:00Added an answer on May 18, 2026 at 10:08 am

    Edited Answer

    Sorry to tell you I have not played with WPF, so just for your question i had to play with it a lil bit 🙂 I answered your question assuming WPF would be almost similar to WinForms.

    So here is the answer 🙂

    DataRowView dr = (DataRowView)(dataGrid1.SelectedItems[0]);
    MessageBox.Show(dr.Row.ItemArray[5].ToString());
    

    dataGrid1.SelectedItems is an array that contains ALL the rows that are selected. So you want the first one from it. If you don’t want your user to select more than one row, set the SelectionMode to Single.

    You first cast the SelectedItem to the type DataRowView, and then you can use it to access your columns of that particular row.

    Sorry for been late and hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I'm new in php and I'm trying to store the numbers from
Hey so I am trying to use Shared Preferences to store information that is
Hey basically Im trying to store a solution and create a vector of these.
Hey all i am trying to find examples of getting data back from a
Hey i'm trying to integrate SFML and Box2D, and SFML has made setting centers
Hey, I'm currently trying to extract information from a 3d array, where each entry
Hey, I'm trying to store an array of pointers (to structs) but am continually
Hey everybody! Im trying to use getLatLng() to geocode a list of postal/zip codes
Hey I'm trying to get this working but I am not a c# programmer.
Hey I am trying to get distance from my current location to another location.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.