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.
Thanks Mike for a prompt answer, as always.
babuman said:Though the code does not crash, the values for the City and State columns are empty when the grid is finally painted.
I'm not sure why it doesn't work. Have you stepped through the code to see if it's actually setting the value of the cell?
babuman said:1. Is e.Row.ListObject is the easiest and the right way to assign or get values or is there another way?
You should probably set the Value of the cell, rather than the ListObject.
babuman said:2. Is InitializeRow is the best place to code this?
Yes.
babuman said:3. What event fires immediatly after InitializeRow? May be I can code after the rows are initalized.
There is no such event.