.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Hide empty row in a datagrid

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :WPF
I am using a datagrid with a hyperlink column that opens a detail
 window using a DataGridHyperlinkColumn. 
I guess that the default datagrid always has an empty row as the 
last row. This means that there is an Edit hyperlink that is not 
associated with an ID. 
Can you either hide that row, so every row is tied to a 'real' 
datarow. Or, can you change the link on the empty row 
to be an Add link that would open the detail window as a 
'New' window? 

<Grid DataContext="{StaticResource eventsViewSource}">
    <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" xmlns:sys="clr-namespace:System;assembly=mscorlib"  Height="200" HorizontalAlignment="Left" ItemsSource="{Binding}" Name="eventsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="544" Margin="21,12,0,0" VerticalGridLinesBrush="LightGray">
        <sys:String x:Key="edit">Edit</sys:String>
        <DataGridHyperlinkColumn Binding="{Bin

View Complete Post

More Related Resource Links

Hide grid view column if empty

 Hello All, I want to hide a grid view column if that column is empty. How do I do this? I dont have much exp. with grids. Please help me. Thanks in advance.

Binding DataGrid to empty DataTable

Hi, I'm very much new to WPF and am finding it a bit tricky to find my way in the mass of (not always great) documentation. Right now I'm struggling to get the grid to display it's UI when bound to an empty datatable. In my XAML: <DataGrid Name="grid" ItemsSource="{Binding}" />  In my code-behind (MainWindow constructor, following InitializeComponent): var dt = new DataTable(); dt.Columns.Add("col1"); dt.Columns.Add("col2"); //var r = dt.Rows.Add("toto", "tata"); grid.DataContext = dt; If I comment out the line that adds a row to the table, all is well -- the grid generates columns and displays UI. But if the table is empty, the grid renders a thin horizontal white rectangle with no column names and it doesn't seem possible to interact with this at all. As it happens, I want the grid to be empty by default, so I need to somehow get the grid to play along. If anyone knows why this happens and what to do to solve it, I'd much appreciate the help!

WPF DataGrid does not show new row on empty linq query

I'm using Linq to Entities and bind a linq query to the WPF 4 DataGrid datacontext.  The linq query look something like this:                  var query = from s in this.db.Customers                         orderby s.Name                         select s;             private ContextEntities db = new ContextEntities();             private BindingListCollectionView View;             this.View = ((BindingListCollectionView)CollectionViewSource.GetDefaultView(query));             this.DataContext = this.View; If my Customers table does not have any record, the DataGrid does not show any row for user to add.  I have CanUserAddRows set to true.  I found another post that address this issue but it say to create a new entity type.  http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cdc0fb6f-2335-42e2-98d7-4bd73ffffc8c My project

Hide the empty rows on dispform.aspx using javascript


Guys, can I hide the empty rows on display form using javascript?

If you know anything, Help me.


Microsoft Matrix Framework DataGrid - Update Command - Convert empty strings to NULL



we have a AutoGenerateColumns-enabled WmxDataGrid in which we are able to update table rows in a DataBase connected with a SqlDataSource.

Each time we clear a field an empty string is written to the database where we want to write DBNull values.

At the moment we generate the update string via UPDATE... SET.. and the SQL Server function NULLIF(value, '').

Works proper but when I want to add the values to e.NewValues in BeginUpdate event I'm not able to read the values from the auto generated text boxes.

How do I do that? Is there an easier way to automatically convert empty strings to NULL values?


Remove/Hide empty space of quick launch from web part page


I created a document library, whose type is "Web Part Pages". When I create a new web part page in this document library the quick launch is missing from the pages. There's a gap on the left side of the web part page for about 200px where the quick luanch would have been.

I don't necessarily want the quick launch to show up at this point. But I don't want the empty space in there either. I would prefer that the web part page covers the empty space on the left side. Can you please advise how to fix this? I had created a subsite before where I don't have this problem.

Let me know if it's not clear about what I mentioned above. Unfortunately I can't post an image here to show what I'm referring to.


DataGrid bound to empty (generic) collection can only add one item


Hi All,

I have a datagrid where the itemssource is bound to an typed observable collection:

ObservableCollection<ItemViewModel> Items;

Initially, the collection is empty (although not null). The datagrid shows me one row, and creates an item in the collection for me automatically. I can edit this row just fine.

However, there is no way of adding a new row. I believe this is because the grid only adds a row when I've finished editing the current one, and since there is but one row I cannot leave that row! I would like to add a fresh row as soon as the user begins editing the current one (bit like the windows forms datagridview).

How can I solve this problem?



how to hide a column in a datagrid but autogenerated columns = "True"?



  Anybody help me please!!! I've 3 datasets named ds1, ds2, ds3. Then i merged that 3 datasets into 1 datatable named dt1. Now, my question is, i want to hide some datacolumns its present in an ds2. How????? Below i attached my code,



connectionString = "provider=MSDAORA;data source=proact;user id=mah;password=mah";


OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);


Using jQuery to HIDE controls leaves an empty space


If one use the jQuery .hide function as follows:

if ($('#<%= rblBlastOccurrences.ClientID %> input:checked').val() == '4763')

$('#<%= pnlBlastWaveExperience.ClientID %>').hide();

How is one to recover/shrink the empty space?

WPF toolkit DataGrid does not show new row with empty collection



I have exactly the same issue present on the post: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cdc0fb6f-2335-42e2-98d7-4bd73ffffc8c

However, the answer is still unclear to me, confusing. So I would like to clarify what do I have to get the new blank row on the datagrid.

My custom collection is called PieceUIObjects (derived from ObservableCollection) containing PieceUIObject objects.

What do I have to change in my collection in order to properly "inform" the datagrid how my object is so that the new row is added on it when the collection is initialized with no elements?

Kindly Regards,


Software Developer and AI Enthusiast. www.twitter.com/ikondrasovas

Remove Default Empty Column From DataGrid

Need to remove extra default column from the datagrid when you bind datagrid with records. In the Image 1 you can see the extra default column when you bind the data grid control. Sometime it is required to remove that extra empty column.

How to format and update GridView and DataGrid rows using JQuery

The behavior described in this question is as expected. When you set text of a cell in grid, it directly affects HTML that is going to be rendered. When you set text value of a cell, it means that you are setting innerText of the cell. The column that GridView creates for command fields (Edit, Delete and Select) are a (anchor) or button elements. So you can see what will happen if you set text value in that cell. It will wipe out those link or button controls and replace them with simple text string.

Hide a repeater in ASP.NET C# if the DataSource contains no items?

I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:
In the (C#) code-behind I'm basically using LINQ to pull a listing of information from an XML document and bind that information to the first repeater.

Searching for the answer to this, it seems the method is to determine whether the data for the nested repeater is empty. If it is, then you set the visibility of the repeater to false.

Use Jquery with repeater, gridview, datagrid

Before we talk about jquery inside any itemtemplate (repeater, gridview, datagrid), we need to understand the basic use of jquery functions

ListBox tricky to set in a DataGrid/GridView

Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:

How to highlight datagrid or GridView row on mouse over?

This article will show how you can Ajax with GridView to display popup messages when mouse moves over certain column. In the demo project I have added first column as an image column with a help icon in it. This kind of implements a feature that if you want more information about the row you can move mouse over this icon, a asynchronous request is sent to server for data about that row and when call returns the returned message is show as a popup message.

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend