Home » WPF

How to get cell values in a listview in C# WPF-urgent

how can I do following



int NumberofChildInALearningStory = SelectedchildInfoListView1.Items.Count;


for (int i = 0; i < NumberofChildInALearningStory; i++)
          int ChildId = **Need to get SelectedchildInfoListView1  row[i] column[1] value**



Can Any one please help me . This is urgent.




how can I do following

 int NumberofChildInALearningStory = SelectedchildInfoListView1.Items.Count;


for (int i = 0; i < NumberofChildInALearningStory; i++)
          int ChildId = **Need to get SelectedchildInfoListView1  row[i] column[1] value**



Can Any one please help me . This is urgent.





5 Answers Found


Answer 1

Is your listView data bound to some data model? Can you show XAML please?


Answer 2

 <ListView Grid.Column="1" Grid.Row="4" Grid.RowSpan="2" Margin="0,6,30,29" Name="SelectedchildInfoListView1" >
                                    <ListView.View >
                                        <GridView >
                                            <GridViewColumn DisplayMemberBinding="{Binding child_ID}" Width="60"/>
                                            <GridViewColumn  DisplayMemberBinding="{Binding family_name}" Width="auto"/>
                                            <GridViewColumn  DisplayMemberBinding="{Binding given_name}" Width="200"/>



data will added as follows

SelectedchildInfoListView1.Items.Add(new { child_ID = SelectedChildID, family_name = familyname, given_name = givenname });


Answer 4

It isn't common practice to work with ListView in that way. 

You should create separate entity (class) MyDataEntity with properties ChildID, FamilyName and GivenName. After that you should create ObservableCollection<MyDataEntity> EntitiesList and data bind ListView to this EntitiesList.

After that you will be able to enumerate EntitiesList in code, perform some magic and changes will be propagated to ListView due to binding mechanism.

If this doesn't help  or you need code sample, please let us know. If this is correct answer mark it as "Asnwer" please.

God bless you!

Answer 5

Hi Tillias,

Thanks for your advice; I managed to do the work as I want. But I would appreciate very much if you could send me some sample code for your proposal.








I have a ListView that consists of single column horizontally oriented.

The cells contains textbox bount to a list.

How do I traverse the cells to access each textbox?


Hello all,

In my GridView I have Hidden column contains ID. When User selects the rows and clicks on Delete Button( This is placed top of the Grid) Selected Rows will be deleted.

my delete button code is ...

foreach (GridViewRow dgi in Grid_Inbox.Rows){

CheckBox chkSelected = (CheckBox)dgi.FindControl("chk_Select");

if (chkSelected.Checked == true)


string strID = dgi.Cells[1].Text;

//Delete the Rows



//Binding the Grid



problem is when i am accessing through the code. getting cell value as blank. plz tell me how to get the hidden value



Wpf 4.0 Datagrid dynamically cells changed value
Hello my friend I have a problemI want to change datagrid cell value

 private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
            DataRowView drv = (DataRowView)dataGrid1.Items[3];
            if (drv.Row["pricetype"].ToString() == "1")

e.Row.Cells[3].Text="Credit Cards"; //not work

How Can I do this ?


I have these 3 columns
CustomerID is not a auto incremnting field
What i want to do is set a default value for CustomerID column when i enter a new record
Im not using a button to enter new records just typing on a new row in the DataGrid


<DataGridTextColumn x:Name="IDColumn" Binding="{Binding Path=ID}" Header="ID" Width="SizeToHeader" />

<DataGridTextColumn x:Name="CustomerIDColumn" Binding="{Binding Path=CustomerID}" Header="Customer ID" Width="SizeToHeader" />

<DataGridTextColumn x:Name="PhoneNumberColumn" Binding="{Binding Path=PhoneNumber}" Header="Phone Number" Width="SizeToHeader" />



I was wondering if there was a simple way of getting the contents (value) of a particular cell in the WPF Datagrid. (In vb.net)
Say a user clicks on a row. i want to be able to get the value of a cell for that particualr row and for a certain column.
This was very simple using the datgrid for windows forms but cannot seem to find a way using WPF,.

hello Friends

I am using WPF Datagrid (WPFToolKit Control) in my appliction

I Have a DataGridComboBox Column which is filled with some records. 

<WpfToolkit:DataGridComboBoxColumnScrollViewer.CanContentScroll="True"CellStyle="{StaticResource LeftAlignedCellStyle}"Header="Item Code"x:Name="CmbItems"Width="250"SelectedValueBinding="{Binding ITEMCODE}"DisplayMemberPath="ITEMDESC"SelectedValuePath="ITEMCODE"  ></WpfToolkit:DataGridComboBoxColumn>
Now how to get selectedText of that combobox for current row. my current focus on other cell 

Please Help Me



Let say I have a wpf datagrid with 2 columns (ProductID and Description).  ProductID column is a combobox and the Description is a Textbox.  On the SelectionChanged event of the ProductID, I want to assign a value to the Description column.  I need to know how to assign the value to the Description textbox for the row of the combobox that fired the SelectionChanged event.  Can you please provide a sample code?  Thanks



Im creating a tool in WPF. I have created list view programatically and add gridviews , gridviewcloumns using FrameworkElementFactor.

 It lookes like this..

Col1           | Col2         | Col3

col1-Values | col2-Values | col3-Button

The gridview's third colum has a button and hooked to a common even handler. Now how will get the listview's row / and its neigbour column's value on cliking the button.

how to get a cell value from datagrid in wpf toolkit to a textbox in the wpf page, when the datagrid selection changed, at runtime.

In my datagrid I assigned the data from database at runtime (that is directly a table vlues from database using itemsource property  of datagrid)

Pls say the answer
I am developing an application using WPF 4.0 Datagrid. My Datagrid grid has one datagridcomboboxcolumn and one datagridtextcolumn. I want to set the combobox selected value in adjacent column's (datagridtextcolumn) cell. How to change the datagrid text cell value using the datagridcomboboxcolumn's SelectedIndex_Changed event?


Why can't I use a string variable for a range location?

Private Sub getFreqCommandButton_Click()

Dim oneCellAboveStartFreq As Long
Dim cellStartLocation As String
Dim startFreq As Long

' search for the start freq indicator text
oneCellAboveStartFreq = Application.WorksheetFunction.Match("VAR_LIST_BEGIN", Range("A1:A1000"), 0)

' return numerical value of row in column A
' = 9 the row where the matched string is located
' writes row number in cell D1
ActiveSheet.Range("D1").Value = oneCellAboveStartFreq

' create  actual cell range where the data is located
' this cell is one cell down - in this case A10
' places the formated data "A10" in cell D2
ActiveSheet.Range("D2").Value = """A" & oneCellAboveStartFreq + 1 & """"

' sets value of D2 to a string variable
cellStartLocation = Range("D2").Value

' now what I really want to get is the data value in cell range A10
' cellStartLocation is equal to "A10"
' so I want to use the variable as the range of the cell I want
startFreq = ActiveSheet.Range(cellStartLocation).Value

' now place the data from A10 in range D3
ActiveSheet.Range("D3") = startFreq

End Sub


I have an application that was working but I made some changes and now I can't seem to modify data in a dataviewgrid.

As soon as I click on a different cell it returns to the original value.  I don't have any cell events except CellDoubleClick.   The other events that I have are RowEnter, RowLeave and DataSourceChange.  The Datasource is a sorted DataView.  I have put break points in all the events and none are getting hit.  Allow* on the dataview are true.  The rows of the datatable isn't readonly.

I am at a loss to understand what what is causing this issue.

Any suggestions?





Please I want to know how I can change the back color of a row based on a cell value using CellFormating event.  The cell visible property is set to false.



I am using a unbound Datagridview Control. Whatever values i set for the cell programmitically, they are not retained. On the other hand, data typed into cells directly are retained correctly.

dgvData is the Datagridview control. I am using the below code in dgvdata's keypress event after checking for return key from keyboard. On going to next row, the previous row cell[0] value disappears.

Is it because it is unbound control or i am missing to update the underlying data structure needed. Please help me solve this. Thanks in advance.


	dgvData.CurrentCell.Value = dgvData.Rows.Count - 1; // Serial No/Row Numberreturn



I am working with multiple queries inside an Excel 2010 (Macro enabled) workbook.  All of the queries are stored in one tab.  They also all have parameters and reference cells within the same tab - set to automatically refresh when the cell value changes.  Some of the values are just numbers; they still seem to work and refresh automatically.  Those that are dates do not refresh automatically - even though they worked properly at one time.  For some reason they don't any longer - I have to manually refresh to actually refresh the data.

What happened?  Why isn't this very useful function working properly any longer?

Please help.



I have a gridview, Which I am editing. If user enter in TxtPrice then I need to caculate, Total  Price. If use enter in txtqunatity then I need to update Total Quantity.

I have added a event  GridCellChanged on OnTextChanged. I need to get cell id and value, How can we get?

 protectedvoid GridCellChanged(object sender, EventArgs e)


//Get Changed Cell Id??





Iam using the  Reporting server 2000 , i want to display the  cell the value as bold,when the value is and if the value is greater then zero, it should display in normal text

problem :

iam able to display the value as bold in normal report and exporting to pdf , but iam unable to show the value as bold while exporting to excel in reporting server 2000.

it is working fine in Reporting server 2003,2008.

please help me if any one know the solution.






   I have a listview control. I have multiple rows & columns. Codded UI can not identify the listview. Instead it mark is as winlist.

How to select elements from 2nd columns?


Hi all!

I've this XAML


            <ListView SelectionMode="Single" Name="lstRecButtonsContesti" <br/>

 ItemsSource="{Binding Path=buttonBarVM.bottoniSec}" BorderThickness="0"><br/><ListView.ItemsPanel><br/><ItemsPanelTemplate><br/><StackPanelOrientation="Horizontal"Width="auto"Margin="0"></StackPanel><br/></ItemsPanelTemplate><br/></ListView.ItemsPanel><br/><ListView.ItemContainerStyle><br/><StyleTargetType="ListViewItem"><br/><SetterProperty="Margin"Value="0"/><br/><SetterProperty="Padding"Value="0"/><br/></Style><br/></ListView.ItemContainerStyle><br/><ListView.View><br/><GridView><br/><GridView.ColumnHeaderContainerStyle><br/><Style><br/><SetterProperty="FrameworkElement.Visibility"Value="Collapsed"/><br/></Style><br/></GridView.ColumnHeaderContainerStyle><br/>

                  <GridViewColumn Width="auto" <br/>

 Header="{Binding Source={StaticResource elencoDizionario}, Converter={StaticResource dizionario}, ConverterParameter=cliente}"><br/><GridViewColumn.CellTemplate><br/><DataTemplate><br/><WrapPanelMargin="0"><br/>

                          <m:SplitButton MouseEnter="SplitButton_MouseEnter" <br/>


             Content="{Binding Path=commessa.IDCommessa}"					<br/>

						VerticalAlignment="Center" <br/>

						HorizontalAlignment="Center" <br/>

						Margin="0" Padding="0" >                         <br/><br/><br/>

The effect I tried to give was like a splitbuttons horizontal array without gaps, but I still have some sort of padding between the buttons.

I've set every possible value of margin and padding to 0 but the empy space still.


Do you have any idea on how can I fix this?


Thank you and sorry for bad english.



I’m navigate to a page called “secondpage”  via my another page called “firstpage” using following code .

secondpage newpage = new secondpage ();


then my “secondpage” will display.

I have a button in the " secondpage " and I want to close this page (secondpage) when I click that button. Then I want to see my previous page (firstpage)  with some values that I entered before I call my “secondpage”.

I would appreciate if any one answers me with a piece of code that I use. I’m using C# in WPF in window base environment.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure