Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
170
Changing value of one cell based on the value of another when rows are initializing
posted

This is a NetAdvantage 2008.1 question (WinForm app)

I have a grid on a windows form that has some columns tied to Dropdowns.  I also have two unbound columns and one of which is also tied to a dropdown.  What I need to know is while initializing rows for the grid, I need to populate these unbound columns based on the value of another bound column.  I have InitializeRow coded something like the following.

  private void igGridCustomers_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  {
In the following code, the "City" and "State" are unbound columns.  Also, "City" is tied to an UltraDropDown.
First, I tried this.  But it crashes in the first iteration with an "Object reference not set" error.

   if (e.Row.Cells["FKZipCodeId"].Value != null)
   {
      e.Row.Cells["City"].Value = ((DataSet1.CustomerAccountsRow)((DataRowView)e.Row.ListObject).Row).ZipCodesRow.CityName;
      e.Row.Cells["State"].Value = ((DataSet1.CustomerAccountsRow)((DataRowView)e.Row.ListObject).Row).ZipCodesRow.StateCode;
   }
   
So, I tried this.  Though the code does not crash, the values for the City and State columns are empty when the grid is finally painted.
   
   if (e.Row.HasCell("City"))
    e.Row.Cells["City"].Value = ((DataSet1.CustomerAccountsRow)((DataRowView)e.Row.ListObject).Row).ZipCodesRow.CityName;
   if (e.Row.HasCell("State"))
    e.Row.Cells["State"].Value = ((DataSet1.CustomerAccountsRow)((DataRowView)e.Row.ListObject).Row).ZipCodesRow.StateCode;
  }

Also, three other questions I have:
1. Is e.Row.ListObject is the easiest and the right way to assign or get values or is there another way?
2. Is InitializeRow is the best place to code this?
3. What event fires immediatly after InitializeRow?  May be I can code after the rows are initalized.

Thanks in Advance.

Babu.

 

Parents
No Data
Reply Children
No Data