1

I want to get the data from a cell from a selected row, in a gridView, and bring it into another form, inside a textEdit that then edit the row of the selected cell, the problem is that when using

var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.toString()) 

the messageBox writes Test01.parnersMissing, where Test01 is the name of the project and I really don't know why PartnersMissing is there. What is wrong in this code? The datagrid has data from an sql database and it is made with DevExpress. Please don't mind the names for the variables if you know italian, I was in a hurry :D

3
  • 1
    Is there a reason why you would not want to just enable edit on gridview itself instead of passing values to another form then edit it there? Commented Mar 21, 2017 at 9:18
  • you are casting the object to a string Commented Mar 21, 2017 at 9:21
  • @P.Pat I want to pass the value automatically because there are many of them, so, passing them one by one is annoying, and because the table content could increase, as other people insert data in the database Commented Mar 21, 2017 at 9:26

2 Answers 2

1

The current row can be obtained using the GridView's GetFocusedRow method. This method returns an object whose actual type is determined according to the data source.

If you are binding it with a List<PartnersMissing> objects then you are getting correct value from the GetFocusedRow method. If you want to access the property of the current row object then you can simply do it.

for example: PartnersMissing has property ABC then you can access as below:

var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.ABC) 

ToString() method returns the type of the object not any property value. you just printing type of the object rather than accessing property of object.

As Dimitry Says, You can also access particular column value or row' PartnersMissing object property using the GetFocusedRowCellValue(String) Method.

Sign up to request clarification or add additional context in comments.

Comments

1

As far as I can see from your code, the result is expected because the cacca.toString() expression return the type name for those types, which do not override the standard object.ToString method.

To show something helpful, you should either to override this method

class PartnersMissing { 
    public string Name { get; set; }
    public override string ToString(){
         return Name;
    }
}

or to obtain the specific values from your object's fields:

MessageBox.Show(cacca.Name);

You can also to obtain the object's fields value directly from the gridView:

string name = gridView.GetFocusedRowCellValue("Name");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.