Hi, I would like to know if it is possible to resize a column depending the length on the content.
For example, I have a product that uses several dynamic fields with contents ranging from 1 character up to (think free-text).
Here's the code I use to generate all fields:
For example, I have a product that uses several dynamic fields with contents ranging from 1 character up to (think free-text).
Here's the code I use to generate all fields:
| DataTable createDataTableWithCustomFields() |
| { |
| NBKCustomer[] custs = c.GetCompetitors(AuthToken); |
| var theVeryLatestNote = custs.SelectMany(cu => cu.OwnerEntity.EntityNotes).OrderByDescending(n => n.Created).FirstOrDefault(); |
| var IamEskimoe = from cuss in custs |
| select new |
| { |
| cuss.CompetitorID, |
| cuss.companyName, |
| cuss.countryRegistrationNumber, |
| cuss.emailAdress, |
| cuss.homepageUrl, |
| cuss.headquarterOrBranch, |
| cuss.legalFormCode, |
| cuss.created, |
| cuss.updated, |
| cuss.branchesQuantity, |
| cuss.OwnerEntity, |
| Notes = cuss.OwnerEntity.EntityNotes.Count(), |
| HasTheLatestNote = (theVeryLatestNote != null ? (cuss.OwnerEntity.EntityID == theVeryLatestNote.OwnerEntity.EntityID) : false) |
| }; |
| DataTable dt = new DataTable(); |
| dt.Columns.Clear(); |
| dt.Columns.Add("CompetitorID", typeof(int)); |
| dt.Columns.Add("companyName", typeof(string)); |
| dt.Columns.Add("countryRegistrationNumber", typeof(string)); |
| dt.Columns.Add("emailAdress", typeof(string)); |
| dt.Columns.Add("homepageUrl", typeof(string)); |
| dt.Columns.Add("headquarterOrBranch", typeof(string)); |
| dt.Columns.Add("legalFormCode", typeof(string)); |
| dt.Columns.Add("created", typeof(DateTime)); |
| dt.Columns.Add("updated", typeof(DateTime)); |
| dt.Columns.Add("branchesQuantity", typeof(int)); |
| dt.Columns.Add("Notes", typeof(int)); |
| dt.Columns.Add("HasTheLatestNote", typeof(bool)); |
| IEnumerable<CustomDataField[]> cols; |
| if (IamEskimoe.Any(i => i.OwnerEntity != null)) |
| { |
| cols = (from i in IamEskimoe |
| where i.OwnerEntity.CustomDataFields.Count() > 0 |
| select i.OwnerEntity.CustomDataFields); |
| foreach (CustomDataField field in cols.SelectMany(f => f).Where(field => !dt.Columns.Contains(field.CustomDataFieldName))) |
| { |
| dt.Columns.Add(field.CustomDataFieldName, typeof (string)); |
| GridBoundColumn col = new GridBoundColumn {HeaderText = field.CustomDataFieldName, AllowFiltering = false, DataField = field.CustomDataFieldName}; |
| grdCI2.MasterTableView.Columns.Add(col); |
| } |
| } |
| else |
| cols = null; |
| foreach (var n in IamEskimoe) |
| { |
| DataRow dr = dt.NewRow(); |
| dr["CompetitorID"] = n.CompetitorID; |
| dr["companyName"] = n.companyName; |
| dr["countryRegistrationNumber"] = n.countryRegistrationNumber; |
| dr["emailAdress"] = n.emailAdress; |
| dr["emailAdress"] = n.homepageUrl; |
| dr["headquarterOrBranch"] = n.headquarterOrBranch; |
| dr["legalFormCode"] = n.legalFormCode; |
| dr["created"] = n.created; |
| dr["updated"] = n.updated; |
| dr["branchesQuantity"] = n.branchesQuantity ?? (object)DBNull.Value; |
| dr["Notes"] = n.Notes; |
| dr["HasTheLatestNote"] = n.HasTheLatestNote; |
| if (cols != null) |
| { |
| var n1 = n; |
| foreach (CustomDataField field in cols.SelectMany(f => f).Where(r => r.FieldData != null && r.FieldData.OwnerEntity.EntityID == n1.OwnerEntity.EntityID)) |
| { |
| dr[field.CustomDataFieldName] = field.FieldData.Data ?? (object)DBNull.Value; |
| } |
| } |
| dt.Rows.Add(dr); |
| } |
| return dt; |
| } |