We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

horizontal scroll bar does not come when i change the binding

Thread ID:

Created:

Updated:

Platform:

Replies:

17302 Aug 5,2004 12:03 PM UTC Aug 9,2004 12:09 PM UTC Windows Forms 9
loading
Tags: GridControl
Umangi
Asked On August 5, 2004 12:03 PM UTC

hi I am using databoundgrid. I am binding it to one data set. On some event I bind it to other data set. First data set has 16 columns. second has 5 columns. When I bind it to second data set and using mouse if expand the column width of any column it does not display the horizontal scrollbar even though It should display

Administrator [Syncfusion]
Replied On August 5, 2004 12:23 PM UTC

After changing your data, try calling grid.Refresh(). You can also try calling grid.Binder.InitializeColumns. Another thing to try is explicitly setting teh colcount after you cahnge the columns with code like: grid.Model.ColCount = this.myDataTable.Columns.Count + 1; //or something that evaluates to your 11 columns If these does not make any difference, can you post the code that shows what you are doing to change the number of columns in the datasource, or better yet, post a sample showing the problem..

Umangi
Replied On 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.

Administrator [Syncfusion]
Replied On August 5, 2004 03:52 PM UTC

You might also try calling this.gridDataBoundGrid1.Model.Cols.Hidden.ResetRange(1, this.gridDataBoundGrid1.Model.ColCount) before you zap the previous data to make sure that the old hidden columns settings are not being retained in the new data.

Umangi
Replied On August 5, 2004 06:20 PM UTC

That''s also not working

Administrator [Syncfusion]
Replied On August 5, 2004 06:46 PM UTC

Try removing your gridModel.Cols.Hidden lines, and only use the LayoutColumns to determine what appears in the grid. If you use LayoutColumns, any columnname not included in the LayoutColumns will not appear in the grid. So, there is no need to try to use Cols.Hidden. If you can post a sample project showing the problem, we can try to spot something here. Or, you can submit a Direct Trac incident with a sample project.

Umangi
Replied On August 6, 2004 06:20 PM UTC

temp_1278.zip Hi Clay here is sample application. On clicking button1 I am displaying one set of data while on button2 I am displaying second set of data. Now Press button1.first set of data will be displayed Then Press button2.second set of data will be displayed. Try to increase the width of first column so that horizontal scrollbar should be displayed. but then also horizontal scrollbar won''t be displayed. Other problem is For first set of data the changed width of column is maintained but for second set of data the width is not maintained. Thanks Umangi

Administrator [Syncfusion]
Replied On August 6, 2004 10:15 PM UTC

I was able to avoid this problem in your sample by setting this.gridDataBoundGrid1.HScrollPixel = true; in FormLoad.

Umangi
Replied On August 9, 2004 10:41 AM UTC

Thanks Clay, This problem is solved. The other problem is still remained. I have loaded first set of data.I change the column width. I load second set of data in grid. Again I load first set of data. The column width is changed width. that''s good that grid maintains the changed widths. But same thing doesn''t work for second set of data. If I load second set of data, change width of any column. Then load first set of data and then again load second set of data the width of that column is default not changed. Could u pls provide some solution? Thanks once again Umangi

Administrator [Syncfusion]
Replied On 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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;