UM
Umangi
August 5, 2004 03:15 PM UTC
Hi Clay
Here are two functions which switches the data in the grid.
private void LoadQueryThreadGridData()
{//The function sets grid appearance and bind the data to grid
try
{
gridModel = gridDataBoundGrid1.Model;
gridBinder = gridDataBoundGrid1.Binder;
gridBinder.ResetHierarchyLevels();
gridDataBoundGrid1.BeginUpdate();
/*here the isDataChanging sets true so if RowEnter event is fired and
it enters in gridDataBoundGrid1_RowEnter function but immediately returns
from there and not execute the code in function which generates exception
*/
isDataChanging = true;
gridDataBoundGrid1.DataMember = "";
gridDataBoundGrid1.DataSource= null;
gridDataBoundGrid1.DataMember = "QueryThreads";
gridDataBoundGrid1.DataSource = m_QueryManagerModel.Data;
gridModel.Options.AllowSelection = GridSelectionFlags.AlphaBlend|GridSelectionFlags.Row|GridSelectionFlags.Keyboard|GridSelectionFlags.Shift;
GridStyleInfo standard = gridModel.BaseStylesMap["Standard"].StyleInfo;
standard.ShowButtons = GridShowButtons.ShowCurrentRow;
standard.CellType = "Static";
// cache grid model and binder
// Reduce flicker
GridHierarchyLevel queryLevel = gridDataBoundGrid1.Binder.AddRelation("QueryThreadQuery");
//Dont show header for Queries
queryLevel.ShowHeaders = false;
isDataChanging= false;
//height of column header
gridDataBoundGrid1.SetRowHeight(0,0,40);
//Set Column headers
SetColumnHeader("CreationReason","Subject");
SetColumnHeader("QueryType","Type");
SetColumnHeader("EndUser", "Created By");
SetColumnHeader("FieldName", "Field \n Label");
SetColumnHeader("SubjectInitials","Initials");
SetColumnHeader("VisitName","Visit \n Name");
SetColumnHeader("Created","Date");
gridModel.Cols.Hidden[0] = true;
gridModel.Cols.Hidden[1] = false;//column of cell with + sign is not hidden
gridModel.Cols.Hidden[2] = true;//threadguid
gridModel.Cols.Hidden[3] = true;//queryguid
gridModel.Cols.Hidden[4] = true;//querytypeguid
gridModel.Cols.Hidden[5] = false;//creationreason
gridModel.Cols.Hidden[13] = true;
gridModel.Cols.Hidden[14]= true;
gridModel.Cols.Hidden[15] = true;//screening number hidden
gridModel.Cols.Hidden[16] = true; //form guid hidden
queryLevel.LayoutColumns(new string[]{"QueryThreadGuid",
"QueryGuid",
"",
"CreationReason",
"QueryType",
"EndUser",
"FieldName",
"SubjectInitials",
"VisitName",
"FormName",
"Created",
"Unread",
"Screening"
}) ;
GridHierarchyLevel queryThreadLevel = gridBinder.RootHierarchyLevel;
queryThreadLevel.RowStyle.BackColor = Color.FromArgb(224,224,224);
queryThreadLevel.HeaderStyle.BackColor =Color.FromArgb( 192, 192, 192 );
gridDataBoundGrid1[0,0].BackColor = Color.FromArgb(192,192,192);
int lastRow = gridDataBoundGrid1.ViewLayout.LastVisibleRow;
gridModel.ColWidths.ResizeToFit(GridRangeInfo.Cells(2, 0, gridModel.ColCount, lastRow), GridResizeToFitOptions.IncludeHeaders|GridResizeToFitOptions.NoShrinkSize|GridResizeToFitOptions.ResizeCoveredCells);
gridDataBoundGrid1.AllowResizeToFit = false;
gridDataBoundGrid1.EndUpdate();
gridDataBoundGrid1.Refresh();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Read();
throw e;
}
}
private void LoadMessageGridData()
{//The function sets grid appearance and bind the data to grid
try
{
gridBinder.ResetHierarchyLevels();
gridDataBoundGrid1.BeginUpdate();
isDataChanging= true;
/*here the isDataChanging sets true so if RowEnter event is fired and
it enters in gridDataBoundGrid1_RowEnter function but immediately returns
from there and not execute the code in function which generates exception
*/
this.gridDataBoundGrid1.DataMember = "";
this.gridDataBoundGrid1.DataSource = m_MessageManagerModel.Data;
isDataChanging= false;
gridModel.Options.AllowSelection = GridSelectionFlags.AlphaBlend|GridSelectionFlags.Row|GridSelectionFlags.Keyboard|GridSelectionFlags.Shift;
GridStyleInfo standard = gridModel.BaseStylesMap["Standard"].StyleInfo;
standard.ShowButtons = GridShowButtons.ShowCurrentRow;
standard.CellType = "Static";
this.gridModel.Cols.Hidden[0]=true;
this.gridModel.Cols.Hidden[1]=true;
this.gridModel.Cols.Hidden[2]=false;
this.gridModel.Cols.Hidden[3]=false;
this.gridModel.Cols.Hidden[4]=true;
this.gridModel.Cols.Hidden[5]=true;
// cache grid model and binder
// Reduce flicker
//height of column header
this.gridDataBoundGrid1.SetRowHeight(0,0,40);
//Set Column headers
SetColumnHeader("CreationReason","Subject");
SetColumnHeader("Created","Date");
standard.BackColor = Color.FromArgb(224,224,224);
GridStyleInfo header = gridModel.BaseStylesMap["Header"].StyleInfo;
header.BackColor =Color.FromArgb(192,192,192);
gridDataBoundGrid1.HScrollBehavior = GridScrollbarMode.AutoScroll|GridScrollbarMode.Automatic;
int lastRow = gridDataBoundGrid1.ViewLayout.LastVisibleRow;
gridModel.ColWidths.ResizeToFit(GridRangeInfo.Cells(2, 0, gridModel.ColCount, lastRow), GridResizeToFitOptions.IncludeHeaders|GridResizeToFitOptions.NoShrinkSize|GridResizeToFitOptions.ResizeCoveredCells);
gridDataBoundGrid1.AllowResizeToFit = false;
if(firstTimeMessageDisplay)
{
setColWidths();
firstTimeMessageDisplay=false;
}
this.gridDataBoundGrid1.EndUpdate();
this.gridDataBoundGrid1.Refresh();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.Read();
throw e;
}
}
And the data which is bound during LoadQueryThreadGridData is
public DataViewManager CreateData(Guid siteGuid,Guid endUserGuid)
{
/*
From buisness class QueryThreadBus and FetchQueries we get Hashtable
It''s not possible to bind hashtable with grid. so in model I generated dataset
which can be bound to grid.
*/
try
{
ds = new DataSet();
DataTable queryThreadTable = new DataTable("QueryThreads");
queryThreadTable.Columns.Add("QueryThreadGuid",Type.GetType("System.Guid"));
queryThreadTable.Columns.Add("QueryTypeGuid",Type.GetType("System.Guid"));
queryThreadTable.Columns.Add("QueryOpenCloseGuid",Type.GetType("System.Guid"));
queryThreadTable.Columns.Add("CreationReason",Type.GetType("System.String"));
queryThreadTable.Columns.Add("QueryType",Type.GetType("System.String"));
queryThreadTable.Columns.Add("EndUser",Type.GetType("System.String"));
queryThreadTable.Columns.Add("FieldName",Type.GetType("System.String"));
queryThreadTable.Columns.Add("SubjectInitials",Type.GetType("System.String"));
queryThreadTable.Columns.Add("VisitName",Type.GetType("System.String"));
queryThreadTable.Columns.Add("FormName",Type.GetType("System.String"));
queryThreadTable.Columns.Add("Created",Type.GetType("System.String"));
queryThreadTable.Columns.Add("Unread",Type.GetType("System.Boolean"));
queryThreadTable.Columns.Add("OpenClose",Type.GetType("System.String"));
queryThreadTable.Columns.Add("Screening",Type.GetType("System.String"));
queryThreadTable.Columns.Add("FormGuid",Type.GetType("System.Guid"));
queryThreadTable.PrimaryKey = new DataColumn[] {queryThreadTable.Columns["QueryThreadGuid"]};
DataTable queryTable = new DataTable("Queries");
queryTable.Columns.Add("QueryThreadGuid",Type.GetType("System.Guid"));
queryTable.Columns.Add("QueryGuid",Type.GetType("System.Guid"));
queryTable.Columns.Add("CreationReason",Type.GetType("System.String"));
queryTable.Columns.Add("QueryType",Type.GetType("System.String"));
queryTable.Columns.Add("EndUser",Type.GetType("System.String"));
queryTable.Columns.Add("FieldName",Type.GetType("System.String"));
queryTable.Columns.Add("SubjectInitials",Type.GetType("System.String"));
queryTable.Columns.Add("VisitName",Type.GetType("System.String"));
queryTable.Columns.Add("FormName",Type.GetType("System.String"));
queryTable.Columns.Add("Created",Type.GetType("System.String"));
queryTable.Columns.Add("Unread",Type.GetType("System.Boolean"));
queryTable.Columns.Add("Screening",Type.GetType("System.String"));
queryTable.PrimaryKey = new DataColumn []{queryTable.Columns["QueryGuid"]};
Hashtable unreadQueries = FetchUnreadQueriesData.GetUnreadQueries(endUserGuid,siteGuid);
int unreadQueriesCount =unreadQueries.Count;
foreach(Object row in FetchQueryThreadsData.GetQueryThreads(siteGuid).Values)
{
QueryThreadRow row1 = (QueryThreadRow) row;
DataRow qThreadRow = queryThreadTable.NewRow();
qThreadRow["QueryThreadGuid"] = row1.QueryThreadGuid;
qThreadRow["QueryTypeGuid"] = row1.QueryTypeGuid;
qThreadRow["QueryOpenCloseGuid"] = row1.QueryOpenCloseGuid;
qThreadRow["CreationReason"] = row1.CreationReason;
qThreadRow["QueryType"] = row1.QueryType;
qThreadRow["EndUser"] = row1.EndUser;
qThreadRow["FieldName"] = row1.FieldName;
qThreadRow["SubjectInitials"] = row1.Initials;
qThreadRow["VisitName"] = row1.VisitName;
qThreadRow["FormName"] = row1.FormName;
qThreadRow["Created"] = row1.Created.ToShortDateString();
qThreadRow["OpenClose"] = row1.OpenClose;
qThreadRow["Unread"] = false;
qThreadRow["Screening"] = row1.Screening;
qThreadRow["FormGuid"] = row1.FormGuid;
queryThreadTable.Rows.Add(qThreadRow);
Guid guid = new Guid(row1.QueryThreadGuid);
foreach(object row2 in FetchQueriesData.GetQueries(guid).Values)
{
QueryRow row3 = (QueryRow) row2;
DataRow qRow = queryTable.NewRow();
qRow["QueryThreadGuid"] = row1.QueryThreadGuid;
qRow["QueryGuid"] = row3.QueryGuid;
qRow["CreationReason"] = row3.CreationReason;
qRow["EndUser"] = row3.EndUser;
qRow["Created"] = row3.Created.ToShortDateString();
qRow["FieldName"] = row1.FieldName;
qRow["SubjectInitials"] = row1.Initials;
qRow["VisitName"] = row1.VisitName;
qRow["FormName"] = row1.FormName;
qRow["Screening"]= row1.Screening;
if(unreadQueries.Contains(row3.QueryGuid))
{
qRow["Unread"]= true;
qThreadRow["Unread"] = true;
}
else
{
qRow["Unread"] = false;
}
queryTable.Rows.Add(qRow);
}
}
ds.Tables.Add(queryThreadTable);
ds.Tables.Add(queryTable);
ds.Relations.Add("QueryThreadQuery",queryThreadTable.Columns["QueryThreadGuid"],queryTable.Columns["QueryThreadGuid"]);
dv = new DataViewManager(ds);
dv.DataViewSettings["QueryThreads"].Sort = "FormName";
m_OpenUnreadQueriesCount = QueriesCountBus.GetUnreadQueries(siteGuid,endUserGuid);
m_ClosedUnreadQueriesCount = unreadQueriesCount - m_OpenUnreadQueriesCount;
return dv;
}
catch(Exception e)
{
Console.WriteLine("Exception");
throw e;
}
}
And the data bound during LoadMessageGridData is
public DataView CreateData(Guid siteGuid,Guid endUserGuid)
{
/*We generate dataview for alert and announcement which we can
* Bind to grid*/
try
{
dt = new DataTable("Messages");
dt.Columns.Add("EndUserMessageGuid",System.Type.GetType("System.Guid"));
dt.Columns.Add("CreationReason",System.Type.GetType("System.String"));
dt.Columns.Add("Created",System.Type.GetType("System.String"));
dt.Columns.Add("IsAnnouncement",System.Type.GetType("System.Int32"));
dt.Columns.Add("IsUnread",System.Type.GetType("System.Boolean"));
dt.PrimaryKey = new DataColumn[]{dt.Columns["EndUserMessageGuid"]};
Hashtable unreadMessages = FetchUnreadMessagesData.GetUnreadMessages(endUserGuid,siteGuid);
Hashtable messages = FetchMessagesData.GetMessages(siteGuid,endUserGuid);
foreach(Object row in messages.Values)
{
MessageRow row1 = (MessageRow) row;
DataRow MessageRow = dt.NewRow();
MessageRow["EndUserMessageGuid"] = row1.EndUserMessageGuid;
MessageRow["CreationReason"] = row1.CreationReason;
MessageRow["Created"] = row1.Created.ToShortDateString();
MessageRow["IsAnnouncement"] = row1.IsAnnouncement;
if(unreadMessages.Contains(row1.EndUserMessageGuid))
MessageRow["IsUnread"]=true;
else
MessageRow["IsUnread"]=false;
dt.Rows.Add(MessageRow);
}
dv = new DataView(dt);
dv.RowFilter = "IsAnnouncement > 0 AND IsUnread=''True''";
m_UnreadAnnouncementsCount = dv.Count;
m_UnreadAlertsCount= unreadMessages.Count-m_UnreadAnnouncementsCount;
return dv;
}
catch(Exception e)
{
Console.WriteLine("Exception");
throw e;
}
}
When the component is loaded LoadQueryThreadGridData()
function is called.
So when I fire event To call function LoadMessageGridData() the scrollbar does not come.
AD
Administrator
Syncfusion Team
August 9, 2004 12:09 PM UTC
You are hiding different columns from one set of data to the next. And the data has different numbers of columns.
So, when you set the width of the 2nd visible column in the first display, that particular column may not be visible in teh next display, or may have a different ''visible col number'' than it had in the first display. So, it is not unexpected that the colwidths are not persisted when you swap data sources and then hide different columns.
If you want the colwidths to persist, then I think you will have to save the ''visible column widths'' in an array before you swap out the data, and then reset the column width in the new display using the saved values. You will have to take into account that the first volumn column in one display may be actually be column 2 in the grid while in the next display, the first visible column might be column 1.