Forms Data Controls :: Column Reorder In Gridview?
Jun 8, 2010
I'm working on a GridView that has around 75 columns. I'm looking for a way the end user can set the order of columns in which he would like to view so that each time he logs in the order is retained.
I'm using following code to reorder listview columns programatically somehow it is showing incorrect behaviuor for certain scenarios. Please let me know if there is any alternative way -
[Code]....
using System; using System.Xml.Serialization; using System.Windows.Forms; using System.Collections; using System.Runtime.InteropServices; namespace TradeDesk { /// <summary> /// This class is used to save and restore the column width and order settings /// for a ListView control. Unfortunately, there is no easy way to obtain the /// order so a Windows message must be sent to the control. This class /// encapsulates that functionality as well as the serialization/deserialization /// of the settings. /// </summary> [Serializable] public class ListViewSettings { [DllImport("user32.dll")] static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, ref LV_COLUMN lParam); [StructLayoutAttribute(LayoutKind.Sequential)] struct LV_COLUMN { public UInt32 mask; public Int32 fmt; public Int32 cx; public String pszText; public Int32 cchTextMax; public Int32 iSubItem; public Int32 iImage; public Int32 iOrder; } const Int32 LVM_FIRST = 0x1000; const Int32 LVM_GETCOLUMN = LVM_FIRST + 95; const Int32 LVM_SETCOLUMN = LVM_FIRST + 96; const Int32 LVCF_ORDER = 0x0020; [XmlElement("ListViewColumns", typeof(ListViewColumn))] public ArrayList listViewCols = new ArrayList(); public ListViewSettings(ListView listView) { try { foreach(ColumnHeader column in listView.Columns) { LV_COLUMN pcol = new LV_COLUMN(); pcol.mask = LVCF_ORDER; bool ret = SendMessage(listView.Handle, LVM_GETCOLUMN, column.Index, ref pcol); listViewCols.Add( new ListViewColumn( column.Text, column.Width, pcol.iOrder )); } } catch {} } public void RestoreFormat(ListView listView) { try { listView.Hide(); for( int i=0; i<listViewCols.Count; i++ ) { foreach( ColumnHeader column in listView.Columns ) { if( column.Text == ((ListViewColumn)listViewCols[i]).header ) { LV_COLUMN pcol = new LV_COLUMN(); pcol.mask = LVCF_ORDER; pcol.iOrder = ((ListViewColumn)listViewCols[i]).order; bool ret = SendMessage(listView.Handle, LVM_SETCOLUMN, column.Index, ref pcol); column.Width = ((ListViewColumn)listViewCols[i]).width; break; } } } listView.Show(); } catch {} } } [Serializable] public struct ListViewColumn { public string header; public int width; public int order; public ListViewColumn(string colHeader, int colWidth, int colOrder) { header = colHeader; width = colWidth; order = colOrder; } } }
I want to display gridview column heading when mouse over to the particular column in the gridview.I am working in VisualStudio 2005 with MS.Net2.0 framework.I don't want to use ajax.
I have a gridview which is binded to a Sqldatasource. I would like to replace a column data field value to 'Not Applicable' if that column has got a value of 2 in database.
I am using GridView ,I want to do a validation like if i edit any one of the Cell in that column, it will through the validation when the sum of column value is more than 100. How can i do this validation?
I have tried several examples of reorder list with several types of data sources and can't get the list to reorder. I have copied Joe Stagner's code from his Video on Reorder Control with the same result. Here is the Video
http://www.asp.net/ajax/videos/how-do-i-the-ajax-toolkit-reorder-control. Page loads, but I can't drag items to reorder. I have tried this with explorer 8 and firefox 3.6, with and without security. Here is the markup, no code behind.
[Code]....
Some of the events don't seem to fire. DataBinding, DataBound, Load, and InsertCommand work ItemReorder does not, (not good for a reorder control). This control should work, but doesn't. I am able to insert data so it seems that the reorder or dragItem templates maybe causing problems. I have commented out but that doesn't help. Here is my only clue, I had to use the script manager from the .net4 Ajax Control Kit for my events to not complain about definitions. I was only using these events with debugger just to see if they are being called, no code in methods. But I am using the toolkit.dll that came with Joe's example. I tried it with .net4 only first, but that didn't work either that's when I installed the dll from Joe's example.
I have the reorderlist and a DELETE as link button. So far so good as far as I can tell that when I clicked on the delete link button, it deletes photo value from the database per the ID PK. However, I want to be able to delete the right photo file on the server/disk (jpg, gif..) but I could not figure out the logic to do so.
As per my requirement, I am getting CompID, Company Name and URL from SQL database. I want to display just CompName and URL in gridvew. So, I need to hide the CompID in gridview. One way I can do BoundField field Visible to false but I need to retrive that compID id when user selected any of the row. if I set visible to false user wont see any compID in gridvew but I want access the selected compID also using SelectedRow.Cells[1].Text..
I have a grid view with 4 columns and 12 rows. Getting the row index is not problem; ;however, I cannot find a way to get the column index of the cell that i select.
how to implement Insert feature to a grid view?I need to use fields with scroll bar inside of a grid view. Is that possible through the template field?
I have one filed that is encrypted using Rajindal algorithm and stored in MSSQL db.When I retrieve that column in gridview it's displayed in encrypted. I have the code that decrypts it but the problem is:How can I all loop throw this column values in the gridview and decrypt them all and display it in the gridview decrypted.See my code below:
I'm facing a wierd problem with GridView and ObjectDataSource. I bind GridView to my business objects via ObjectDataSource. Everything was working fine until I decided to add a new field in my buisness object and wanted to add a column to GridView to show it. Somehow that column is NOT shown in the GridView's list of available columns. I have tried refreshing schema, rebinding, etc. I'm using GridView inside a user control which is used as a web part. Does that make a difference ?
I want to use a value of a column from a selected row in a gridview as default value of a dropdownlist on a form on the same page. how to get this done in VB?
how to get first column value of each row in Gridview?
i am writing like this:
int Total=0; for (int i = 0; i < GridView1.Rows.Count; i++) { Total += = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text); //it does not have column value }s