1

I am working on project where I need help and direction on displaying master child rows with object as datasource

I have following issues, please kindly help me

1) How to Assign the objectdatasource to data grid so that user can click master row to see child rows

2) Once master child data shown in grid, user can edit any column, if user clicks any column I have to re calculate the values. How to do that?

For example: if user is editing product price then I have to calculate the net price. I am not sure how to implement this functionality. Where I have to put my calculation logic and how to call my calculation logic from Grid?

Please let me know what the best way of doing above tasks. i have done some research but unable to find out clear example on implementation

Thanks,

beginner
  • 39
  • 7

1 Answers1

0

If you don't already, you need to make sure your class is a composite. In other words:

class Child
{
   int ChildId { get; set; }
}

class Parent
{
   int ParentId { get; set; }
   List<Child> Children { get; set; }
}

From here, Dev Express will do all of the heavy lifting for you.

Let's say you have two grids, gridMaster and gridChild. Create Two binding sources, bindMaster and bindChild.

In the designer, make the DataSource for the bindMaster an object of type Parent. Make the DataSource for bindChild bindMaster (not the object Master) and set the DataMember property to "Child."

Now, when you refresh the data for the master and select rows, the child grid will automatically populate to whatever master record's children are -- without any hand-written code!

Here is an example from another similar question:

Devexpress master-detail in 2 gridcontrols

As far as the product price / net price, you have two options:

  1. Make an unbound column in the grid

  2. (my preference), add the property directly to the object

Something like this would work:

public double ProductPrice { get; set; }
public double NetPrice
{
    get { return ProductPrice * Quantity; }
}

You might have to fire a RefreshData() on the Grid View if the data in the grid changes, but I'd test it first to see if it's necessary.

Community
  • 1
  • 1
Hambone
  • 15,600
  • 8
  • 46
  • 69
  • ,Thank you for your help on how to calculate netprice, i need further help on Grid control and views, as you mentioned i have already composite classes but i think i can't use multiple grids because of multiple classes public class child { public int ChildId { get; set; } public List toys {get;set;} } public class Toys { public string toyname { get; set; } public int toyprice { get; set; } } ..etc i think i need to use one gridcontrol with multiple views, can you please help me how can i do with single grid? – beginner Nov 04 '16 at 06:29
  • If you use a single grid, it's even easier -- just bind the one grid, and it will automatically create a master/detail view. What issues are you having? – Hambone Nov 04 '16 at 11:48
  • Hi Thanks, i am able to display master and child rows using single grid with level designer . need further help, as per my requirement i want to display master row with first child info how can i do that for example right now Master row looks like below ------| Parent ID | if i expand child row looks like below ------| child ID| but i want to display master row as -----------|--- ParentID,| child id| if i expand child row should look like ----------- child id ( child row is displaying fine) – beginner Nov 05 '16 at 00:33
  • Can you update your question with this detail? It's hard to follow in the comment. – Hambone Nov 05 '16 at 01:15