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

Post New Web Links

WPF ListViewItem not Stretching to GridViewColum

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :WPF
Hey, I have a problem with a TextBox in a DataTemplate of a ListView, using GridViewColumn. The issue is the TextBox doesn't fill the column, resulting in a TextBox which is really thin, only changes its width according to the containing data length. Setting the HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" doesn't change a thing. Here is the code: <Grid> <Grid.Resources> <DataTemplate x:Key="IONumItemTemplate"> <Border BorderThickness="0,0,0,0" BorderBrush="#6FBDE8"> <Grid> <TextBlock Text="{Binding IONum}" VerticalAlignment="Center"/> </Grid> </Border> </DataTemplate> <DataTemplate x:Key="IOValItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBox Text="{Binding IOVal, Mode=TwoWay}" Width="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Column="0"/> </Grid> </DataTemplate> &

View Complete Post

More Related Resource Links

Get all ListViewItem cells

Hi again, I need to iterate throug all cells on each ListViewItem. I know that I could use the underlying collection, but it doesnt fit my needs. The underlying collection doesnt know wich converters or format have been applied to each column, it also doesn't know which columns are being displayed and which are not, it doesn't know which column header has been used for each property, and so on. I know I could work with the underlying collection and apply every convertion-translation-filter-formating-sorting-headering again, but it doesn't appear to be practical. I just know that that I can see already displayed, is what I have and it is also what I need. If I can see what I need, could be so hard to get it? This is what I did just to notice what I have said (GetValue is a custom function that just gives the underlying property value):   foreach (Object item in source.Items) { PropertyInfo[] dataFields = item.GetType().GetProperties(); foreach (GridViewColumn col in grid.Columns) { try { //Get the name of field displayed on grid string strPath = ((Binding)col.DisplayMemberBinding).Path.Path; //Get the field value object propValue = GetValue(item, source.Items, strPath); } catch (Exception) { } } }   The previous code doesn't fit my needs... I need something like:  

Remove a dynamically added ListViewItem from a ListView

Good day, In my xaml I have created a window in my app which contains a  ListView control. I have programmatically added ListViewItems. The ListViewItems each contain a grid. Grid column 0 contains a textblock, Grid column 1 contains a textbox and Grid column 2 contains a button. What I would like to do is click the button in the ListViewItems grid, and remove the ListViewItem in the button is contained from the ListView. Could anyone suggest a way to do this? I would really appreciate any advice, as this is crucial to the feature I am creating.

C# WPF ListView: ListViewItem content will not update?

I am having a problem updating a listview item which I have bindings set. Here is my XAML code and behind code. Also, the DownloadProgress and DownloadSize do not update but when I debug I see the changes made under the DownloadProgressChanged delegate: mtitem.dlbtn.MouseLeftButtonUp += delegate { MTDLItem dlitem = new MTDLItem(); dlitem.DownloadName = mtitem.tbmusicname.Text; dlitem.DownloadProgress = 0; dlitem.DownloadSize = ""; WebClient wc = new WebClient(); Uri webaddress = new Uri(mtitem.MusicLink); if (mtitem.Group == "5") { } else { string songtitle = mtitem.tbmusicname.Text + @".mp3"; string fixtitle = songtitle.Replace("\\", ""); if (Properties.Settings.Default.CopyRightMessage == false) { if (System.Windows.Forms.MessageBox.Show("GINtech Systems is not responsible for user applications of copyrighted music which may be in violation of existing local, state, or federal laws.", "MusicTuner Disclaimer", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Exclamation) == System.Windows.F

Is it possible to not allow a listviewitem to not be selectable based on a state condition?

I have a listview that is binded to a collection. The listview contain items with different states and would like to know how to not allow an item with a specific state to not be selectable. Does anyone know how I can achieve that? I do know that I can add some kind of datatrigger, multitrigger in xaml but just don't know how to implement it. Any help is appreciated. Thanks in advance.

Display ListView inside ListViewItem???

Hi,   I was first using a tree view in order to display a two level hierarchical structure, however this was too slow (tree was taking up to 10 sec to display 3000 items). I believe that a listview will improve this performance. Is it possible to have a listview inside the listviewitem? So far I have this, the first level is being displayed, but no the second level Please help!! <ListBox x:Name="lstBoxHitList" Padding="5" Margin="1" ItemsSource="{x:Static local:Window1.SearchJobsList}" DockPanel.Dock="Bottom" MouseDoubleClick="tvHitList_MouseDoubleClick" TreeViewItem.Selected="tvHitList_Selected" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <ListBox.Resources> <Style TargetType="ListBox" x:Key="ListBoxControlStyle" BasedOn="{StaticResource {x:Type ListBox}}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" Value="0"> <Setter Property="Template"> <Setter.Value> <ControlTemplate>

WPF - How to acces the tags of 3 comboboxes inside a ListViewItem


Hey I have the following problem:

I have a form with a ListView on it and this listview consists of listviewitems with some kind of template which is defined in the gridcolumn celltemplate.  The listview has elements of type "LeidingViewModel.cs" and that class consists of a Property Choices, which in turn consists of 3 observablecollections, which I want to bind on the 3 comboboxes inside the listviewitems. This isnt a problem, I know how to do this.

When I select something from the combobox I want the tag of the first combobox in a listviewitem to contain the choices of all 3 comboboxes together, I have done this using multibinding.  And now comes the problem: how can I acces the tag of the first combobox, when that combobox in fact is declared in a <DataTemplate> and referenced to from the ListView.View GridView.GridViewColumn.CellTemplate?.

Here's my code:

<Window ... xmlns:local="clr-namespace:PiconSalesWPF">

WPF: how to make the listview work (apply basic listviewitem style and also apply special data


 We have defined the basic ListViewIItemStyle as following:

<!--ItemContainerStyle with the Trigger for selection x:Key="ListViewItemStyle"-->
 <Style x:Key="ListViewItemStyle"
  TargetType="{x:Type ListViewItem}">
 <Setter Property="Background"
 Value="Transparent" />
 <Setter Property="HorizontalContentAlignment"
 Value="Center" />
 <Setter Property="VerticalContentAlignment"
 Value="Center" />
 <Setter Property="Foreground"
 Value="Black" />
 <Setter Property="Margin"
 Value="5,0,5,0" />
 <Setter Property="MinHeight"
 Value="40" />
 <Setter Property="Template">
 <ControlTemplate TargetType="{x:Type ListViewItem}">
 <Border x:Name="Bd"
 <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
 <!--<ContentPresenter HorizontalAlignment="Left"
  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />-->

Nested ListView: Parent listview item auto selection on child ListViewitem select


how can i auto select paraten listview item on selecting child listview item?

ListView ItemContainerStyle="{StaticResource myStyle}" Name="lv_list" Margin="5" HorizontalContentAlignment="Stretch">

How to write ListViewItem that contain image , text and button ?


I need to write some listViewItem  ( using WPF ) - that contain image, text and button.

I want to inherit from the simple listViewItem class and add to the listview item that contain the three items ( image, text, button ).

I don't understand how the listView control will arrange the 3 items ( image , text, button ) in the right order in the control - how to tell the listview control that the image is first, text is second and the button is the third ?  




I'm currently trying to convert my WindowsForms application to WPF, however I have run into some trouble with a ListView.
For instance, this worked before:

ListViewItem lvItem = new ListViewItem(Convert.ToString(clientId));
        lvItem.SubItems.Add(lastname + " " + forename);


But SubItems doesn't seem to do the trick anymore?
Anybody have any suggestions?

ListViewItem and Command handling?


Hello, I have defined a window under MVVM approach. Everything works great, but I found a little problem.

I have a ListView with items from a collection, all that I want is to track the SelectedItem changes to a command.


        <Label Grid.Row="1">Points</Label>

Setting ZIndex of grouped ListViewItem doesn't bring ListViewItem to top

I created this simple example to show what I am trying to support in my application. If you run this and hover over one of the listview items in the middle column, it will not be brought to the top and is partially covered by the items in the column to the right.

I'm setting the ZIndex on that ListViewItem, why is not brought to the top? I'm thinking the grouping is part of the problem, but I'm not sure how to fix this. Any suggestions would be great!

<Window x:Class="MRBListViewSample.MainWindow"


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