.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

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

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :WPF
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

View Complete Post

More Related Resource Links

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

Binding byte[] to image control in navigation application leaks

Hi there, I have a (minimal) navigation application with two pages. Page1 contains an image. Switching between pages is done via a buttonhandler in code behind, for instance, (this.NavigationService.Navigate(new Page2())) The image is loaded in code behind via: private void LoadImage() { string fileName = "./images/image.bmp"; if (!new FileInfo(fileName).Exists) throw new Exception("File name doesn't exist"); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { this.ImageData2 = new byte[fs.Length]; fs.Read(this.ImageData2, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); } } ImageData2 is a byte[] property that sends a propertychange event on changing. ImageData2 is bound to an image in xaml: <Image Grid.Row="1" Source="{Binding Path=ImageData2, Mode=OneTime}"/> When we unload Page1 the following clean up code is executed private void Page_Unloaded(object sender, RoutedEventArgs e) { this.ImageData2 = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Now, when I start changing pages, I expect the Page we leave to unload, so the GC removes the byte array. However, it doesn't. Am I missing something? Binding the image to a BitmapImage (ImageData1, as you might have guessed:-) ) doesn't leak.

Print control works on reporting server, but not in embedded in application

Hi,I am having an issue where if I click on the print icon in the report viewer embedded in an application, I get the error "unable to load client print control".  However, when running through report manager, this is fine.  I am running SQL Server 2005 SP3 and report viewer 9.Any thoughts would be much appreciated.

How to enable own shortcut within WebBrowser control in Windows form application




I am developing a windows form application with C#, where I have placed WebBrowser control... I load some web page in this webbrowser and I need to know, that after I press my own certain shortcut that it will allow me to call my handler...

It should work something like this => I have certain textbox on web page and after pressing my own shortcut, it will call my handler which will automatically type certain text (which will be prepared in that handler) into that textbox... 

Could you advice me, how to make this happen or if it is even possible?


Thanks a lot in advance

adding windows user control in asp.net application


hi fri i had created one user control in c# and i want to add this user control in asp.net application pl tel me how to do this

thanks in advance

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

hosting a WPF control library in a WF application


When I try to integrate a WPF control library in a WF code activity object I get the exception "The calling thread must be STA, because many UI components require this."  Here is a snippet:


private void OpenGUI()


           //Load GUI

           mainGUI = new WPFControlLibrary.UserControl_GUI();



When the mainGUI = line is executed, I get the error.

Please excuse my ignorance, I am a novice in WF and WPF.


Thanks in advance for any help.

Problem hosting a WPF user control in a windows form application

I have a windows forms application and want to to use WPF inside this application. So I have add a WPF user control into my project. Then I take a ElementHost from the toolbox and put it on my windows forms. The problem is now, when I want to add the WPF control with "Edit Host Content" I get the message "This ElementHost is currently not hosting any editable content....." What's wrong? How can I embed my implemented WPF control into the ElementHost ?

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?

Can we use SharePoint People Picker Control in DotNet Application?


Hi all,

We want to use SharePoint People Picker Control in .net application to validate the users. So is it possible to use the People Picker Control in .net application?

Please give me the suggestion...... thanks in advance...

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

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