.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

Bringing SelectedItem Into Focus Using DataGrid Control

Posted By: Asim Sajjad     Posted Date: December 04, 2011    Points: 2   Category :Silverlight
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.

View Complete Post

More Related Resource Links

SelectedItem of DataGrid Control

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.

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

How to set the border for a WPF DataGrid Row which is currently having the focus

Hi, I want to set the border for a DataGrid Row which is currently having the focus. But not the seleced row because when the Multi selection is enabled for the datagrid then there is a chance that multiple rows can be selected. I need a solution in XAML Thanks in advance! Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.

Premature loss of focus in WPF user control

I have a user control that consists of a dockpanel, inside of which are a textbox, a stack panel (containing two user controls), and another user control.  I am handling the LostFocus event for the dockpanel.  Since LostFocus deals with Logical Focus in WPF parlance, one would logically (pun intended) assume that if one was to click anywhere inside the dockpanel, the LostFocus event should NOT be fired for that control.  However, it appears that If I click anywhere outside of the textbox in the dockpanel, the LostFocus event is fired.  I am not using custom focus scopes since there are multiple of these user controls in my WPF window and I only want one of them to have focus at any given time. I've read many blogs and articles on WPF focus issues and so far nothing has worked.  Any help would be highly appreciated.

How to determine when focus moves into a RowDetails panel in a DataGrid?

Is there a recommended way of determining when focus moves from the selected row into the details panel and knowing which field the focus is on? I don't really want to wire up all the controls in the panel, so am looking for a better way - all suggestions appreciated:-)

page.setfocus(listbox.selecteditem) is not setting the focus if index > 820

Hi All, Does any one know the reason Why I am unable to setfocus to my list box if the index > 820 My list box contains 2000 items and the index is not  able to set the focus if the index > 820  

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="

Set focus on erronous control on validation inside ajax tabcontrol having 5 tab


Hiii.. Everybody

How to set the focus on textbox when requiredfield validator error mesage comes to action inside the ajax tabcontrol.The ajax tabcontrol is having 5 tabs.The submit button is in 5th tab .I have reqiredfield validator for textbox  in 1st tab.I want to set the focus on textbox if validation fails.Is it possible to get without postback????

Is there anyone can help me out ????

Thanks in advance

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

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