Data Grid - Displaying a related column instead of parent id - URGENT HELP PLEASE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dawnyy
    New Member
    • Dec 2007
    • 3

    Data Grid - Displaying a related column instead of parent id - URGENT HELP PLEASE

    I'm in desperate need of knowing how I can bind my data grid so that I have the following

    Customer ID - parent table
    Customer Name - parent table
    Status ID - parent table
    Status Description - related table status

    I want to pull in the status description from the relation I have set up on the dataset between the customer table and the status table based on the status ID!

    Does anyone know how to do this?

    I tried going into edit columns on the grid and changing the DataPropertyNam e to the Foreign Key link and the Status Description column, but the data does not appear!

    I am filling the customer and status tables in the load event of the form.

    Any help would be greatly appreciated!
  • agarwalsunitadhn
    New Member
    • Jan 2008
    • 82

    #2
    Originally posted by Dawnyy
    I'm in desperate need of knowing how I can bind my data grid so that I have the following

    Customer ID - parent table
    Customer Name - parent table
    Status ID - parent table
    Status Description - related table status

    I want to pull in the status description from the relation I have set up on the dataset between the customer table and the status table based on the status ID!

    Does anyone know how to do this?

    I tried going into edit columns on the grid and changing the DataPropertyNam e to the Foreign Key link and the Status Description column, but the data does not appear!

    I am filling the customer and status tables in the load event of the form.

    Any help would be greatly appreciated!

    why dont you try to manually bind the datagrid with coding
    like this

    OleDbConnection conn=new OleDbConnection (conectionstr);
    string str="select pt.CustomerId,p t.CustomerName, pt.StatusId,rt. StatusDesc from parenttable pt,relatedtable rt where rt.CustomerId=p t.CustomerId";
    OleDbCommand cmd=new OleDbCommand(st r,conn);
    OleDbDataAdapte r ada=new OleDbDataAdapte r(cmd);
    DataSet ds=new DataSet();
    ada.Fill(ds);

    Datagrid.DataSo urce=ds;
    DataGrid.DataBi nd();

    and must set AutoGenerateClo mns to false from datagrid property

    I think this code will must help

    Comment

    • shlabadoo
      New Member
      • Feb 2008
      • 4

      #3
      I'm not sure if this works for DataGrids, but for a DataGridView you can set a column to be a ComboBox instead of a textbox. Then you can set both the display property and the value property to the other table.

      When you change it to a dataGridViewCom boBoxColumn you get some other options in the Data section of the edit columns dialog.

      There is DataPropertyNam e, DataSource, DisplayMember, and ValueMember. Set the DataPropertyNam e to the key that you are trying to not show, the DataSource to the binding source of the secondary table, DisplayMember to the name of the column you want to actually display and ValueMember to the primarykey of that table.

      Then you can change the DisplayStyle to Nothing to get rid of the dropdown arrow.

      Hopefully that pertains to your situation.

      -dan

      Comment

      Working...