Hi,
I am facing a peculiar issue. I have added a Ultragrid on a form and doing some preprocessing in the InitializeRow event. Now, occasionally, when the form is loaded, I can see rows but no data. This doesn’t seems to be an data issue since when I click on any row, all rows gets ‘refreshed’ and data is displayed in all cells. Below is an image where you can see how rows are displayed.
Any suggestions/solutions will be hugely appreciated.
Hello Jaita,
Thank you for posting. You mentioned that you did some preprocessing in the InitializeRow event, may know what you did? Could you provide the code?
How did you set up the grid ? Also, may I know which version control you are using?
How did you set up the grid/data source? Please provide more information or a small isolated sample for further investigation.
Looking forward to hear you back.
Sincerely,
Divya Jain
Associate Software Developer
Hello Divya,
Thank you for the response. Please find the answers to your questions as below,
You mentioned that you did some preprocessing in the InitializeRow event, may know what you did? Could you provide the code?
private void ugdTimePhase_InitializeRow(object Sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
// // ** Place Event Handling Code Here **
if ((e.Row.Band.Index == 0))
e.Row.ExpandAll();
}
if ((e.Row.Index >= (tpDataView.Table.Rows.Count - 1)))
// messagebox.show( e.row.index.tostring & " / " & tpDataView.Table.rows.count.ToString )
UpdateTimePhase();
private void UpdateTimePhase() {
// messagebox.show("Here")
bool Changed = false;
int PONum = 0;
string Text = "";
bool ok = false;
int RowNum = 0;
DataTable tblTimePhase = tpDataView.Table; // tpDataView is the view to which Grid is bounded.
// dim tblTimePhase as DataTable = TimePhas_DataView.Table
if (!tblTimePhase.Columns.Contains("POHeld")) {
tblTimePhase.Columns.Add("POHeld", System.Type.GetType("System.Boolean"));
if (!tblTimePhase.Columns.Contains("POConfirmed")) {
tblTimePhase.Columns.Add("POConfirmed", System.Type.GetType("System.Boolean"));
if (!tblTimePhase.Columns.Contains("ColourCode")) {
tblTimePhase.Columns.Add("ColourCode", System.Type.GetType("System.String"));
foreach (DataColumn col in tblTimePhase.Columns) {
// setting extended properties didnt work for readonly
col.ExtendedProperties["ReadOnly"] = true;
POAdapter poAD = new POAdapter(TimePhasForm);
poAD.BOConnect();
foreach (DataRow dr in tblTimePhase.Rows) {
RowNum = (RowNum + 1);
// messagebox.show(cstr(RowNum) & "=" & dr("PONum") & ", " & dr("ColourCode") )
if ((dr["ColourCode"] == DBNull.Value)) {
Changed = true;
dr["POHeld"] = false;
dr["POConfirmed"] = false;
dr["ColourCode"] = "n/a";
if ((Int32.Parse((string)dr["PONum"]) > 0)) {
ok = false;
try {
ok = poAD.GetByID(dr["PONum"]);
catch (Exception ex) {
MessageBox.Show(ex.Message);
if (ok) {
bool Confirmed = (bool)poAD.POData.POHeader[poAD.POData.POHeader.Rows.Count - 1]["Confirmed"];
bool Hold = (bool)poAD.POData.POHeader[poAD.POData.POHeader.Rows.Count - 1]["OrderHeld"];
dr["POHeld"] = Hold;
dr["POConfirmed"] = Confirmed;
Text = "n/a";
if ((Confirmed == true)) {
Text = "G";
if (((Hold == true)
|| (Confirmed == false))) {
Text = "R";
dr["ColourCode"] = Text;
if (Changed) {
tpDataView.Table = tblTimePhase;
tpDataView.Sort = "DueDate";
poAD.Dispose();
Please let me know if you need any further details. Looking forward to hear you back.
If I am reading this correctly, this code is very strange. You are checking to see if the Index of the row in InitializeRow is the same or higher than the count of rows in the DataTable that the grid is bound to. And if so, you are then adding new columns to that Table.
Adding new columns to the grid's data source inside of InitializeRow is probably not a good idea and I can easily imagine how that might cause the InitiializeRow event to get called recursively or cause weird timing issues and behavior like you are getting here. It also doesn't really make a lot of sense to me. Why would you want to do that only when you get to initialize a particular row number? You should really just add those columns to your data source before binding it to the grid.
And BTW, you are making a bad assumption there about the row index. You are assuming that the row index is going to line up with the count of the rows in the data source, but that's not necessarily true. If you are sorting the grid, for example, then the grid row whose Index matches the count-1 of your data source will not be the same row.