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

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

SelectedItem of DataGrid Control

Posted By: Asim Sajjad     Posted Date: August 25, 2011    Points: 2   Category :Silverlight
This is very basic question which every beginner has ask many time on the forum "How to get selected Item of the datagrid control". So in this post I will answer this question and some more detail about the selected item of the datagrid control.

View Complete Post

More Related Resource Links

Bringing SelectedItem Into Focus Using DataGrid Control

When using datagrid control of the silverlight control there is situation when datagrid control has lots of records and vertical scrolling of the datagrid control is visible and the selected item of the datagrid control is not in the view as the scrolling (vertical scrolling of the datagrid is visible due to large record). So it is important to give focus to the selected item of the datagrid control.In this post I will give you solution of this problem which many of you may have face.

A datagrid control that can be personalized... anyone??


Hello all,

I need a datagrid control that has following features, besides other regular stuff like paging, sorting, filtering, etc:

The user should be able to -

1. Select columns to view

2. Select column Sequence

3. Select default sort column

4. Store the setting (as a view) and use it on next visit.

5. llow multiple such views to be stored for a user for future use.

All these settings should be saved and when the user comes back he gets the same settings.

Really appreciate your time and would love to get any ideas.


- Zen

Using DataGrid for my application - is it the right control?

I've been investigating DataGrid for my embedded application.  Basically, what I want to do is to read in information from my embedded system over USB.  Store the information in a structure.  And, retrieve the information from the structure to display to the user.   The information I want to display is an ID Number (1-255), an ID Description, and a Relay Number.  The Relay Number is a drop down combo box with 4 options of 1-4, which is editable by the user.  The ID Number is not editable and the Grid should contain information all 1-255 IDs.  The Description should be a maximum, editable, field of 30 characters (I might change later).  Is the DataGrid the best way to do this? I tried to implement a DataGrid (see below), but am having some problems getting the data into the columns correctly.  Do I need both the Header entries in WPF and in the code?  When I do, I get two columns of 'ID #' and 'IDNum' with 1-255 in each column.  I don't want the header 'IDNum', only 'ID #' as stated in the WPF code.  I'm missing something.  Maybe someone can help.  Thanks. Sutton     <DataGrid Height="287" HorizontalAlignment="Left" RowHeight ="20" Margin="12,96,0,0" VerticalAlignment="Top" Name="PointZoneDataGrid" DataContext="{Bi

Expand control with DataGrid in wpf


i have a problem,

iam using a datagrid and in datagrid every row has a expander control with mentain a comments. my problem is whenever i expand that time datagrid is also expand and again whenever i collapse then some space is meintain in bottom of datagrid how can i solve this.

another thing is that iam using a datagrid.Items.Refresh(). but when datagrid refresed comments is also clear...plz give me a solution immediately

DataGrid control properties not updating on resize event


I have a DataGrid control on a form and I'm binding it to an ArrayList that is populated dynamically as the user scrolls.  The array list is pre-populated with blank records equal in number to the number of records in the DB.  As the user scrolls, if they stop in a place where there are blank records I populate that data from the DB.  I'm using the VisibleRowCount and VertScrollBar.Value properties to determine where I am in the DataGrid.  


The problem is that if I scroll to the bottom of the control then maximize the control it's resize event fires, the VertScrollBar is redrawn proportionally to the number of records, but the Value and VisibleRowCount remain unchanged.  If I then grab and scroll the scroll bar up then back down to the bottom, the Value and VisibleRowCount update correctly.  Is there a way for me to get these values some other way or to force the scroll bar to refresh/update manually?

Is there any free wpf DataGrid Control that have events similar to web ones?


WPF DataGrid control has limited events that do not support my needs.

Is there any free wpf DataGrid Control that have more useful events?

Access a control placed inside header template of a datagrid in WPF



I have a requirement to add filters to a datagrid. I have placed the filter controls in the headertemplate of a datagrid. How can I access these controls in code behind? I need to set itemsource for the listbox placed in header template through code behind on the basis of certain selections by user. Following is my data template(resource template) for header column.

<DataTemplate x:Key="buttonResourceTemplate">
      <StackPanel Name="spResource" FlowDirection="LeftToRight" Orientation="

Datagrid view control producing duplicate data results when data is cached


I have a datagridview control that I'm using to display cache data to the end used on a web form. The issue that I'm having is that every time I re-run the application, and the cache data is re-generated... it loads duplicate data that's being displayed to the end user. I can't seem to figure out how to keep this from happening.

What I would like to have happen is that only unique data rows be returned and cached for the end user. Unless there are new data rows on the database that needs to be included in the cache data results...the previous data results should not be duplicated. I've tried to change a few properties on the datagridview control, but nothing seem to keep this from happening. I have included a copy of my code below. Any help would be greatly appreciated.


' Code that is used to cache data that's returned from database

Protected Sub PopulateNewhardwareSetInfo()

   Dim conn As SqlConnection = New SqlConnection(m_connectionString)

   Dim cmd As SqlCommand = New SqlCommand("Select * from HardwareSet", conn)  

   Dim sqlDA As SqlDataAdapter = New SqlDataAdapter(cmd)      

   sqlDA.FillSchema(m_ItrackerData, SchemaType.Source, "HardwareSet")

DataGrid in a User Control. How to make it resizable in a form.


I embed the DataGridView control in a User Control.  The datagridview covers the entire user control.

When I used the user control in a form, I want to be able to size it the way I want to.  When I expand and shrink the user control, I want the embedded DataGridView to grow and shrink accordingly with the user control.  How would I go about doing that?

Without changing any of the default property values, when I place the user control on a form, the size stays fixed when used in a form.  That seems to happen only when you have a DataGridView in a user control.  

Thanks in advance.

.Net 4.0 DataGrid Control Horizontal ScrollBar Issue



I'm using .Net 4.0 DataGrid control to display my data using databinding. The data are displayed correctly but there is an issue with the horizontal scrollbar:

My datagrid has 15 columns and window when displayed is not showing all the 15 columns. This is okay as the window width limit the number of visible columns. So, as not all columns are visible, there is a horizontal scroll bar. If I drag the horizontal scroll bar at once to the right of the datagrid, it will appear to be moved to the end right but it really go just to the middle. So even If moved the horizontal bar to the end right, it did not go all the way ! I was expecting it to go all the way.

If I keep dragging the horizontal scroll bar to the right until it reach the end, at that time, the scroll bar works properly. I can then move it to the left, and move it to the right end and this time it will go all the way.

Is this is a known issue ? Any workaround so the scroll bar go all the way to the right when dragged to the complete right ?

Important detail: I'm using columns virtualization (EnableColumnVirtualization="True"). If i turn off the columns virtualization, the issue

does not occur.

how to get a cell control in DataGrid


Dear everyone

i have tried to get a cell control in datagrid, but i can't get it.



        void SimPle_Loaded(object sender, RoutedEventArgs e)

        Microsoft.Windows.Controls.DataGridCell cell = GetCell(1, 1);
            TextBlock tb = cell.Content as TextBlock;   // i can't get the textblock, the cell.content have a binding object, not control
            if (tb != null)


          //<Output:OutputIO x:Name="WriteOutput" BorderThickness="6" Height="38" Width="150" IO="{Binding Mode=OneTime, Path=IOHandle}"  />

         // because i want to get my usercontro

Edit a DataGrid row's style by Javascript when a control is clicked.


I have a datagrid I am working with which has a few columns, but one checkbox with a javascript onclientclip event.

I want to highlight the row that the checkbox is clicked, highlighting for the user that this record has changed.

I have a CSS Class of "GrdHiglight" that can be used to override the "GrdNorm" and "GrdAlt" classes, or if I have to manually change the style for the row that is fine.

How do I reference the one row which the checkbox resides in, in the datagrid, to modify this?

Selecting One Checkbox Control In DataGrid Control Using MVVM Using Silverlight

In this post I will show you how to select single check-box control when you have single check-box control in each row of the datagrid control. As you all know that check-box controls are normally used for the multiple selection and radio buttons are used for single selection. But there are sometimes requirement that control should be check-box and selection should be single. Mean if user view data in the datagrid control then he/she should only select one check-box at a time not more then one. Main page is shown in the Image 1. Here you can see that I have placed check-box control in the first column of the datagrid control which I have also highlighted.

Best Way to Use PagedCollectionView With Datagrid Control

I have used Paged Collection view whenever I need to create application which has data grid control to display the item in tabular format. I used to new collection every time I get data and then create new Paged collection view. In this post I will show you how to use one collection and update it. Which I think is best practice to use the Paged collection view with data grid control.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.
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