10 Replies - 3403 Views - Last Post: 04 December 2010 - 07:12 AM Rate Topic: -----

#1 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

extract data from datagrid

Posted 04 December 2010 - 06:18 AM

Hey looking to find out how to extract data from datagrid and then store it

dataGrid1.CurrentRow.Cells[0].Value.ToString(); //where [0] was the ID column in my gridview


how do I then store that value?

This post has been edited by Sparukus: 04 December 2010 - 07:10 AM

Is This A Good Question/Topic? 0
  • +

Replies To: extract data from datagrid

#2 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: extract data from datagrid

Posted 04 December 2010 - 06:23 AM

Where do you want to store it?

Also take a look at:
http://www.dreaminco...sics-in-c%23/#/

This post has been edited by Sergio Tapia: 04 December 2010 - 06:25 AM

Was This Post Helpful? 1
  • +
  • -

#3 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: extract data from datagrid

Posted 04 December 2010 - 06:32 AM

Just in a string, that code however doesnt work. Just an example, I need it more for "user selected" to give an example if I delete a user from my database I first must select the user from my datagrid. Thats easy right. But what about when I select and go to hit my button I need it to "store" the selected users imagePath.

Once I can do that im all set for doing my ftp delete as all I will have to do is ftpFileDelete(ipAddy, + imagePath)

And im done! Just not sure how to grab the imagepath upon selecting the user to delete.
        private void button2_Click(object sender, RoutedEventArgs e)
        {
                    // method to extract imagePath coloum from datagrid 
            Stu 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))
                {

                    Class1.DeleteStu(selected);
                    Window_Loaded(null, null);

                    // ftp delete image via imagePath from datagrid
                }
            }

This post has been edited by Sparukus: 04 December 2010 - 06:37 AM

Was This Post Helpful? 0
  • +
  • -

#4 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: extract data from datagrid

Posted 04 December 2010 - 06:37 AM

You can use:

dataGridView1[0, 0].Value.ToString();

Was This Post Helpful? 1
  • +
  • -

#5 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: extract data from datagrid

Posted 04 December 2010 - 06:52 AM

nah that doesnt work. [] isnt valid and values isnt valid?
Was This Post Helpful? 0
  • +
  • -

#6 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: extract data from datagrid

Posted 04 December 2010 - 06:56 AM

Works on my machine. Are you getting an exception? You're probably getting an index out of bounds exception because your grid is empty. Please post error codes when seeking help. We aren't mind readers. :)
Was This Post Helpful? 1
  • +
  • -

#7 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: extract data from datagrid

Posted 04 December 2010 - 07:03 AM

Error 1 'System.Windows.Controls.DataGrid' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.Windows.Controls.DataGrid' could be found (are you missing a using directive or an assembly reference?)





Cannot apply indexing [] to an expression of type to system.windows.controls.datagrid

This works

dataGrid1.Columns.[0, 6].Value.ToString();


but not sure how to add it to the "selected items"

This post has been edited by Sparukus: 04 December 2010 - 07:01 AM

Was This Post Helpful? 0
  • +
  • -

#8 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: extract data from datagrid

Posted 04 December 2010 - 07:05 AM

Is this an ASP application or a Webforms application?

DataGrid
http://msdn.microsof...rid(VS.80).aspx

DataGridView
http://msdn.microsof...tagridview.aspx

Are two different controls.
Was This Post Helpful? 1
  • +
  • -

#9 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: extract data from datagrid

Posted 04 December 2010 - 07:07 AM

wpf form
Was This Post Helpful? 0
  • +
  • -

#10 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1252
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: extract data from datagrid

Posted 04 December 2010 - 07:09 AM

In your initial post you were using a DataGridView, now you're using a DataGrid. It's hard to help when you change around like that and not even let us know.
Was This Post Helpful? 1
  • +
  • -

#11 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: extract data from datagrid

Posted 04 December 2010 - 07:12 AM

o very sorry, i did indeed.

Yeah so something like:

string imagePath;
dataGrid1 selected items coloum 6 to string.

Then I can call my string in my ftp delete sequence.

This post has been edited by Sparukus: 04 December 2010 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1