private void SetGridCols()
        {
            //This pattern is wrong.
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col;

            fields = DisplayFields.GetForCategory(DisplayFieldCategory.PatientSelect);
            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Description == "")
                {
                    col = new ODGridColumn(fields[i].InternalName, fields[i].ColumnWidth);
                }
                else
                {
                    col = new ODGridColumn(fields[i].Description, fields[i].ColumnWidth);
                }
                gridMain.Columns.Add(col);
            }
            gridMain.EndUpdate();
        }
        private void FillGrid()
        {
            Cursor = Cursors.WaitCursor;
            gridMain.BeginUpdate();
            List <DisplayField> fields = DisplayFields.GetForCategory(DisplayFieldCategory.CEMTSearchPatients);

            if (gridMain.Columns.Count == 0)           //Init only once.
            {
                foreach (DisplayField field in fields)
                {
                    string heading = field.InternalName;
                    if (string.IsNullOrEmpty(heading))
                    {
                        heading = field.Description;
                    }
                    gridMain.Columns.Add(new ODGridColumn(heading, field.ColumnWidth));
                }
            }
            gridMain.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < _dataConnPats.Tables.Count; i++)
            {
                for (int j = 0; j < _dataConnPats.Tables[i].Rows.Count; j++)
                {
                    row = new ODGridRow();
                    foreach (DisplayField field in fields)
                    {
                        switch (field.InternalName)
                        {
                            #region Row Cell Filling
                        case "Conn":
                            row.Cells.Add(_dataConnPats.Tables[i].TableName);
                            break;

                        case "PatNum":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["PatNum"].ToString());
                            break;

                        case "LName":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["LName"].ToString());
                            break;

                        case "FName":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["FName"].ToString());
                            break;

                        case "SSN":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["SSN"].ToString());
                            break;

                        case "PatStatus":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["PatStatus"].ToString());
                            break;

                        case "Age":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["age"].ToString());
                            break;

                        case "City":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["City"].ToString());
                            break;

                        case "State":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["State"].ToString());
                            break;

                        case "Address":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["Address"].ToString());
                            break;

                        case "Wk Phone":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["WkPhone"].ToString());
                            break;

                        case "Email":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["Email"].ToString());
                            break;

                        case "ChartNum":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["ChartNumber"].ToString());
                            break;

                        case "MI":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["MiddleI"].ToString());
                            break;

                        case "Pref Name":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["Preferred"].ToString());
                            break;

                        case "Hm Phone":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["HmPhone"].ToString());
                            break;

                        case "Bill Type":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["BillingType"].ToString());
                            break;

                        case "Pri Prov":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["PriProv"].ToString());
                            break;

                        case "Birthdate":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["Birthdate"].ToString());
                            break;

                        case "Site":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["site"].ToString());
                            break;

                        case "Clinic":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["clinic"].ToString());
                            break;

                        case "Wireless Ph":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["WirelessPhone"].ToString());
                            break;

                        case "Sec Prov":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["SecProv"].ToString());
                            break;

                        case "LastVisit":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["lastVisit"].ToString());
                            break;

                        case "NextVisit":
                            row.Cells.Add(_dataConnPats.Tables[i].Rows[j]["nextVisit"].ToString());
                            break;
                            #endregion
                        }
                    }
                    row.Tag = ListConns.Find(x => ((x.ServerName + ", " + x.DatabaseName) == _dataConnPats.Tables[i].TableName || x.ServiceURI == _dataConnPats.Tables[i].TableName));
                    gridMain.Rows.Add(row);
                }
            }
            gridMain.EndUpdate();
            Cursor = Cursors.Default;
            if (_complConnAmt == ListConns.Count)
            {
                ODThread.QuitSyncThreadsByGroupName(1, "FetchPats");               //Clean up finished threads.
                butRefresh.Text    = Lans.g(this, "Refresh");
                labelFetch.Visible = false;
                if (!_hasWarningShown && _invalidConnsLog != "")
                {
                    _hasWarningShown = true;                  //Keeps the message box from showing up for subsequent threads.
                    MessageBox.Show(this, Lan.g(this, "Could not connect to the following servers") + ":" + _invalidConnsLog);
                }
            }
            else
            {
                butRefresh.Text    = Lans.g(this, "Stop Refresh");
                labelFetch.Visible = true;
            }
        }