.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

Can't style selected item in ListView when GridView is used

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :WPF
Below is a simple window that contains a ListView. Note that it is overriding the SystemColors.HighlightBrushKey to change the color of the selected item.
Works fine, unless  the ListView.View block is enabled, and a GridView is defined.

When that is done, the GridView seems to enforce its own idea of what the selected row should look like.

How can I style the selected row of a ListView using a GridView?

<Window x:Class="WpfApplication1.Window3"
    Title="Window3" Height="300" Width="300">


View Complete Post

More Related Resource Links

ASP.NET 4.0 Menu Top Level selected item style


I want to apply a css class to the level 1 menu item (parent) when it or any or it's children are selected.

I've looked at MSDN documentation and any number of examples and walkthroughs but I haven't come up with a way of managing this. I was thinking something like this might work but the style is not being applied to the parent. To further complicate matters, if I try to apply a css style to StaticSelectedStyle it doesn't pick it up at all.

Menu Markup:

<StaticSelectedStyle  Font-Bold="True" ForeColor="#3333CC" />

Code Behind:

        protected void MenuItemClick_NavMenu(Object sender, MenuEventArgs e)


            MenuItem parentItem = e.Item.Parent;

            if (parentItem != null)


                parentItem.Selected = true;



VS2008 and C#: How to create a short cut for a selected item in a ListView/TreeView ?

How to create a short cut for a selected item from a ListView/TreeView ? Is it possible to provide a smaple code ? Thanks,

Display the item in the ComboBox inside the ListView(GridView)

I have the below code used in binding the values to the ComboBox in GridView(ListView), please help me < ListView Margin="480,51,6,14" Name="grid1" ItemsSource="{Binding UserDetail}" IsSynchronizedWithCurrentItem="True" Width="389" Grid.Column="1" > <ListView.View> <GridView> <GridViewColumn Header="UserName" Width="120" DisplayMemberBinding="{Binding Path=WindowsUser}"/> <GridViewColumn Header="Role" Width="140"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox Name="Rolecombo" Width="120" ItemsSource="{Binding Path=UserDetail}" SelectedValue="{Binding PFR_Tbl_Role.Role}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Active" x:Name="column" Width="100"> <GridViewColumn.CellTemplate> <DataTemplate> <Grid Width="{Binding ElementName=column,Path=Width}"> <CheckBox IsChecked="{Binding Active}" HorizontalAlignment="Center" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView>  </ListView.View> </ListView>

ListView.ItemTemplate with Button. Command doesn't execute when item is selected

I have a listview with an item template that contains a button: <ListView ItemsSource="{Binding AllProducts}"> <ListView.ItemTemplate> <DataTemplate> <Grid> <Button Content="Add Supplier" Command="{Binding AddSupplier}"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> When the listitem is not selected and the button is clicked, the command executes fine. However, if the listitem is selected, the command does not execute. I have tried putting click and mouse down event handlers on the button, but the events do not fire. Is there any way to make the command execute when the listitem is selected?

Listview selected item with Linkbutton


<asp:ListView ID="pricedRoomListView" runat="server" DataKeyNames="room_id" DataSourceID="pricedRoomsObjDataSource"
                            EnableModelValidation="True" OnItemDataBound="pricedRoomListViewOnItemDataBound" OnItemCommand="bidRoomFromListView">
                                <tr style="background-color: #E2E6FC;">

Listview & GridView , select an item




i create a ListView with a GridView and some GridViewColumn´s in therein:

<ListView ItemsSource="{Binding Records}" x:Name="list" Margin="21,8,21,18.9" Grid.Row="2" Background="{StaticResource linearbrush2}" HorizontalContentAlignment="Center">
      <GridViewColumn  DisplayMemberBinding="{Binding hd_drive}" Width="35" Header=" Drive"/>
      <GridViewColumn  DisplayMemberBinding="{Binding browser_name}" Width="100" Header="Browsername"/>
      <GridViewColumn x:Name="defaultbrowserpath" DisplayMemberBinding="{Binding file_path}" Width="300" Header="Path" /> 

the DisplayMemberBinding-Property points to a ObservableCollection, with the Name Records,

Listview/gridview checkbox is selected or not



I have a question about checkbox in listview or checkbox. How do I know when checkbox is selected or not? Do I have to add Binding or..

Import-Module wpk
Add-Type -AssemblyName presentationframework

[xml] $xaml = @"
  Title="MainWindow" Height="350" Width="525">
    <ListView Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" Margin="3" Name="ListView1" SelectionMode="Extended">
 <GridView AllowsColumnReorder="true">
 <GridViewColumn Header="ServerName">               
      <CheckBox Margin="-4,0,-4,0" IsChecked="False" Name="nupp" Content="{Binding ServerName}"/> 

On row selected in gridview populate Listview.


Hi I have a problem with populating a ListView...

When the row is selected in the gridview control I want to bind data to listview.. When Im using a SQL datasource in Listview then

its working fine .. For example :

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:UserProfilesConnectionString %>"
                SelectCommand="SELECT .... FROM.... WHERE ([ArticleID] = @ArticleID)"
                    <asp:ControlParameter ControlID="GridView1" Name="ArticleID"
                        PropertyName="SelectedValue" Type="Int32" />

A Simple and Extensible Radio Button Style GridView

The GridView is one of the significant controls in ASP.NET 2.0 and later versions. No doubt it reduces a lot of work time. However, customizing the GridView control is not an easy task. For example, it's hard to add a radio button column to the GridView. This article demonstrates the reason why a radio button column cannot act as normal and how to create a simple and extensible radio button GridView.

Gridview that exports selected rows to Excel

his seems like a messy workaround, but I ended up using two Gridviews - one to display my data and show my checkboxes, and the other which was invisible amd would eventually end up as my Excel spreadsheet.

How to let user edit selected gridview columns, not entire row



I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?


Rendering data with HTML tags in the DD Gridview for a selected column


I am having trouble finding out where and how to HTML Encode a cell's data on the Dynamic Data (v4.0) gridview of List.aspx.  As a simple case, suppose I have formatted cell data that is A<br/>B in the DB.    Obviously, I want A stacked on B in the cell.

It seems gridView1.HtmlEncode = true has gone away.

So maybe I'll try to catch it on the RowDataBound event:

protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)

            if (e.Row.RowType == DataControlRowType.DataRow)
                // Html Encode the cells


but this event never fires?

Has anyone figured out how to properly render HTML tags data in the List.aspx's GridView1? 

If I figure this out, then I can add a MetaAttribute called something like [EncodeAsHtml(true)] and be on my way.  Thanks!

How to keep the hover for Parent menu and set the selected menu item css for child menu item?



I'm using cssfriendly control adapter for menu. My asp.net menu control's datasource is a sitemap file I'm using which contains all the urls.

I have the following questions:

  1. Is there a way to keep the parent menu item hovered while hovering over the respective child menu items?
  2. Is there a way to keep the child menu item selected? I am able to set the css for the parent menu, however I was wondering if the same is possible with the child items.

Please help! Smile


Moneka Smile

problem...i want a list item to populate all data in gridview!!!


i have a dropdownbox and a gridview

what I want is to have a list item which populates all data in a gridview.

I have tried using list item selected value=0 but to no avail.

what is the easiest way to achieve this?

Manually coding controls such as gridview, listview, repeater, etc.


using vs2010 and .net 4

In my project I have a separate DAL built from class files that I'd like to use to store my code for CRUD operations against my database.

I'm having a hard time finding examples of how to code server controls like the gridview, listview, repeater etc., for CRUD operations manually, i.e., without a datasource control of some flavor.

I don't have any problem manually coding the referenced controls to get my data, but I do have problems when it comes to coding them to perform CRUD operations unless I use a datasource control. When I use the datasource controls CRUD operations seem to automagically appear out of nowhere after they're configured.

Can someone point me to some samples somewhere? Have I missed a section at MSDN?


Dynamically Populate a DVWP depending on selected item



I am wanting to create a dashboard page with several data view web parts which dynamically populate depending on what item is selected in a separate web part (drop down form or just a list of links).  Can someone please point me to a tutorial or documentation on how to pass data between web parts or to a DVWP?  I have searched for a few hours and not been able to find anything useful.



listview 3.5 bind dropdownlists edit item template VB.NET


I am trying to do this with many issues of data binding doubling the amount and not setting selectedValue on dropdownlist. I have read some posts and they help but I am missing a crucial piece. My problem is that my dropdownlist is doubling the amount of records for the dropdownlist. Instead of "YES;NO;SELECT A VALUE", I am getting "YES;NO;SELECT A VALUE;YES;NO;YES;NO". My database is correct with the UPDATE part but the rebind after update is failing horribly.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Session("ACTIVETAB").ToString() = Session("SUBCONTRACTSATABNO").ToString() Then
            End If
        End If
    End Sub

    Public Function loadlookups(ByVal id As String, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) As DataTable
        Select Case id
            Case "ddlCertReceived"
                dt = GetLookupTable("SubcontractsA", "Sub 1 Cert Received")
                Dim ddlCertReceived As DropDownList = _
                CType(e.Item.FindControl("ddlCertReceived"), DropDownList)
                ddlCertReceived.DataSource = dt
                ddlCertReceived.DataTextField = "lup_text"
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