dataview

DataTable sorting with Datacolumn Name with comma

╄→гoц情女王★ 提交于 2019-12-01 19:39:16
I have data table showing statistics of different cities for different periods. It has following columns names Period | city1,state | city2,state | city3,state Jan 15 25 20 Feb 5 26 29 Mar 35 27 21 I have applied some logic and it gives me column name to sort the respective column name and bind the data again with grid on front End. Now problems comes when I tried the following code for sorting griData.DefaultView.Sort = string.Format("{0} {1}", orderByField, sortDirection) Because of the comma in the column name it treats it as two columns and give exception. Example: If I am sorting by

Sorting a List<FileInfo> by creation date C#

陌路散爱 提交于 2019-12-01 16:58:44
Using this example off MSDN: using System.Collections.Generic; using System.IO; namespace CollectionTest { public class ListSort { static void Main(string[] args) { List<FileInfo> files = new List<FileInfo>(); files.Add(new FileInfo("d(1)")); files.Add(new FileInfo("d")); files.Add(new FileInfo("d(2)")); files.Sort(new CompareFileInfoEntries()); } } public class CompareFileInfoEntries : IComparer<FileInfo> { public int Compare(FileInfo f1, FileInfo f2) { return (string.Compare(f1.Name, f2.Name)); } } } How would I compare the date of creation. F1 has a property "creation" date which is a

Create ADO.NET DataView showing only selected Columns

99封情书 提交于 2019-11-30 19:13:58
In C# & .NET, can one create a DataView that includes only a proper subset of the DataColumn s of a given DataTable ? In terms of relational algebra, one assigns a RowFilter in order to perform a "selection" operation (σ). How would one perform a "projection" operation (π)? You can't do that, but you can create a copy of the table with only the columns you want : DataView view = new DataView(table); DataTable table2 = view.ToTable("FirstColumn", "SecondColumn", "ThirdColumn"); Optionally you can return rows that have distinct values for the selected columns : DataView view = new DataView(table

How to get a value from a column in a DataView?

谁说胖子不能爱 提交于 2019-11-30 19:04:24
I have a dataview defined as: DataView dvPricing = historicalPricing.GetAuctionData().DefaultView; This is what I have tried, but it returns the name, not the value in the column: dvPricing.ToTable().Columns["GrossPerPop"].ToString(); You need to specify the row for which you want to get the value. I would probably be more along the lines of table.Rows[index]["GrossPerPop"].ToString() You need to use a DataRow to get a value; values exist in the data, not the column headers. In LINQ, there is an extension method that might help: string val = table.Rows[rowIndex].Field<string>("GrossPerPop");

How Can Convert DataRow to DataRowView in c#

半世苍凉 提交于 2019-11-30 17:51:22
Can or how to convert DataRow to DataRowView? For example: DataTable dt=ds.Tables[0]; DataRow dr= dt.NewRow(); DataRowView drv = ???? BizApps Use DataTable dt=ds.Tables[0]; DataRow dr= dt.NewRow(); DataRowView drv= dt.DefaultView[dt.Rows.IndexOf(dr)]; The above method does not work if the DataRow status is Detached. This code snippet could be used in such case: DataRow dRow = dataTable.NewRow(); //... DataRowView dRowView = dRow.Table.DefaultView.AddNew(); for (int i = 0; i < dRow.ItemArray.Length; i++) { dRowView.Row[i] = dRow[i]; } DataRowView selecRow = dataTable.DefaultView.Cast

Rearrange items of DataView with Drag and Drop

有些话、适合烂在心里 提交于 2019-11-30 16:40:04
I have an ExtJS DataView with following template: <ul> <tpl for="."> <li class="report-field" id="{listId}"> {[this.getReorderLinks(values, xindex, xcount)]} <span class="field-title small" data-qtip="{displayName}">{displayName}</span> <i class="field-remove" title="' + deleteLabel + '"></i> </li> </tpl> </ul> Which makes each list of items look like this: Where user can click on different icons and perform related action, moving up/down in order and remove. Note that these items are added to dataview using Drag and Drop, where there's another source dataview container from which I drag the

Sorted dataview to datatable

杀马特。学长 韩版系。学妹 提交于 2019-11-30 11:44:47
I have the following method: private DataTable getsortedtable(DataTable dt) { dt.DefaultView.Sort = "Name desc"; //I would need to return the datatable sorted. } My issue is that I cannot change the return type of this method and I have to return a DataTable but i would like return it sorted. Are there any magic hidden property of dt.DefaultView to return the dt sorted? FosterZ private DataTable getSortedTable(DataTable dt) { dt.DefaultView.Sort = "columnName DESC"; return dt.DefaultView.ToTable(); } do this private DataTable getsortedtable(DataTable dt) { //do the operation for sort return

How to sort a DataView in a case-insensitive manner?

那年仲夏 提交于 2019-11-30 09:34:03
问题 I have a DataTable. I'd like to sort its default view by a column name 'city'. I'd like the sort to be case-insensitive. Here is the code I have: DataTable dt = GetDataFromSource(); dt.DefaultView.Sort = "city asc"; MyReport.DataSource = dt.DefaultView; Thanks. 回答1: Never mind. It's in the documentation. DataTable dt = GetDataFromSource(); dt.CaseSensitive = false; dt.DefaultView.Sort = "city asc"; 来源: https://stackoverflow.com/questions/521795/how-to-sort-a-dataview-in-a-case-insensitive

How to get a value from a column in a DataView?

こ雲淡風輕ζ 提交于 2019-11-30 03:10:52
问题 I have a dataview defined as: DataView dvPricing = historicalPricing.GetAuctionData().DefaultView; This is what I have tried, but it returns the name, not the value in the column: dvPricing.ToTable().Columns["GrossPerPop"].ToString(); 回答1: You need to specify the row for which you want to get the value. I would probably be more along the lines of table.Rows[index]["GrossPerPop"].ToString() 回答2: You need to use a DataRow to get a value; values exist in the data, not the column headers. In LINQ

Sorted dataview to datatable

喜欢而已 提交于 2019-11-29 17:18:10
问题 I have the following method: private DataTable getsortedtable(DataTable dt) { dt.DefaultView.Sort = "Name desc"; //I would need to return the datatable sorted. } My issue is that I cannot change the return type of this method and I have to return a DataTable but i would like return it sorted. Are there any magic hidden property of dt.DefaultView to return the dt sorted? 回答1: private DataTable getSortedTable(DataTable dt) { dt.DefaultView.Sort = "columnName DESC"; return dt.DefaultView.ToTable