Binded Datagrid displays System.Data.Datarow as data

Using VS2010 C#
Hi All,
I am having a really annoying issue which I know there's an easy fix for, but i cannot figure it out for the life of me. My goal is to copy info from an excel sheet to the datagrid. To achieve this, I am taking the clipboard and creating a datatable, and
from the datatable --> datagrid. I have finally got the datagrid to display the correct column names and number of rows, but the records are showing "System.Data.Row" instead of the row's ItemArray. I've debugged the datatable and the correct
info is right there in the ItemArray properties. Can someone please help me resolve this issue?
Thanks in Advance!!!
Here's my code:
private void button1_Click(object sender, RoutedEventArgs e)
string s = System.Windows.Clipboard.GetText();
string[] lines = s.Split('\n');
string[] columnsNames = lines[0].Split('\t');
lines = lines.Where(w => w != lines[0]).ToArray();
DataTable dt = new DataTable();
DataRow dr;
List<DataRow> list = new List<DataRow>();
foreach (string str in columnsNames)
dt.Columns.Add(str, typeof(string));
DataGridTextColumn dgtxcol = new DataGridTextColumn();
dgtxcol.Header = str;
dataGrid1.Columns.Add(dgtxcol);
dgtxcol.Binding = new Binding(".");
for (int row = 0; row < lines.Length; row++)
string[] rowInfo = lines[row].Split('\t');
dr = dt.NewRow();
for (int z = 0; z < rowInfo.Length; z++)
if (rowInfo[z].Contains('\r'))
rowInfo[z] = rowInfo[z].Replace('\r', ' ');
dr[columnsNames[z]] = rowInfo[z];
dt.Rows.Add(dr);
list = dt.AsEnumerable().ToList();
dataGrid1.ItemsSource = list;
string name = ((DataRow)dataGrid1.Items[0]).ToString();
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
e.Row.Header = (e.Row.GetIndex()+1).ToString();
<Window x:Class="ClipboardToWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="846" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
<Grid>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" Height="346" HorizontalAlignment="Left" Margin="12,103,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="800" LoadingRow="dataGrid1_LoadingRow" CanUserAddRows="True">
</DataGrid>
<Button Content="PASTE" Height="39" HorizontalAlignment="Left" Margin="691,33,0,0" Name="button1" VerticalAlignment="Top" Width="96" Click="button1_Click" />
</Grid>
</Window>

Since the DataContext of a DataGridRow is an item in the DataGrid's IEnumerable<T> ItemsSource, you must specify the column name or property name of T to bind to for each column. "." just binds to the DataRow itself.
You must also remove the \r also from the column name. You can then set the ItemsSource property of the DataGrid to the DefaultView of the DataTable itself.
The following modified code seems to work fine for this sample data:
col1 col2
val1 val2
private void button1_Click(object sender, RoutedEventArgs e)
string s = System.Windows.Clipboard.GetText();
string[] lines = s.Split('\n');
string[] columnsNames = lines[0].Split('\t');
lines = lines.Where(w => w != lines[0]).ToArray();
DataTable dt = new DataTable();
List<DataRow> list = new List<DataRow>();
foreach (string str in columnsNames)
string name = str.Replace("\r", "");
dt.Columns.Add(name, typeof(string));
DataGridTextColumn dgtxcol = new DataGridTextColumn();
dgtxcol.Header = name;
dataGrid1.Columns.Add(dgtxcol);
dgtxcol.Binding = new Binding(name);
for (int row = 0; row < lines.Length; row++)
string[] rowInfo = lines[row].Split('\t');
DataRow dr = dt.NewRow();
for (int z = 0; z < rowInfo.Length; z++)
if (rowInfo[z].Contains('\r'))
rowInfo[z] = rowInfo[z].Replace('\r', ' ');
dr[z] = rowInfo[z];
dt.Rows.Add(dr);
dataGrid1.ItemsSource = dt.DefaultView;
string firstname = dt.Rows[0][0].ToString();
Hope that helps.
Please remember to mark helpful posts as answer to close the thread and then start a new thread if you have a new question.

Similar Messages

  • How to display system date

    I want to display system date in portal pages. Is there any template subsitution tags or any easy way of displaying date.
    Without using 'javascript'
    Thanks
    Manjith

    You could put something like the following into a PLSQL item or a Dynamic Page portlet (between <ORACLE></ORACLE> tags) - change the date formatting and add any html/css that you need to display the date the way you want:
    DECLARE
    todaysdate VARCHAR2(12);
    BEGIN
    select TO_CHAR(SYSDATE,'MON DD, YYYY') INTO todaysdate FROM DUAL;
    htp.print(todaysdate);
    END;Note: this code could probably be simplified a bit, I just pulled this snippet out of something I use that does more than just display the sysdate.

  • Jstl tags to display System date.

    Hi there,
    Please let me know how to how to display system date on jsp page using jstl.
    I dont know much about jstl, and i was till now using java code in jsp instead of jstl.
    Since using java in jsp is considered a bad programing these days, I dont want to use java
    to display the date.
    Can anyone help me switch to jstl tags.
    Please help me with the date issue.

    [This will help you|http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html] learn what JSTL tags are available. Once you get that it should be relatively easy to figure out what you nee. If you have questions on a particular tag then a [Google search almost always|http://www.google.com/search?q=jstl+fmt%3AformatDate] brings up example usage.

  • The system failed to flush data to the transaction log. Corruption may occur.

    We have a windows server 2008 R2 Virtual machine and we are getting the following Warning Event.
    Event 51 Volmgr
    The system failed to flush data to the transaction log.  Corruption may occur.
    Any idea what is wrong with this server? Why this event is occurring?

    Hi Jitender KT,
    Before going further, would you please let me know the complete error message that you can find (such as a
    screenshot if you can provide)? Please check and confirm in Event Viewer if there other related event you can find, such as Event 57 and so on. Meanwhile, can you remember what operations you have done before the warning occurred?
    Based on current message that you provided, please run
    Chkdsk command to check if you can find error. The issue seems to be related to the storage device. Please refer to the following similar question.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/044b10af-c253-46de-b40d-ce9d128b83d7/event-id-57-source-volmgr?forum=winservergen
    In addition, please also refer to the following link. It should be helpful.
    http://www.eventid.net/display-eventid-57-source-volmgr-eventno-8865-phase-1.htm
    Hope this helps.
    Best regards,
    Justin Gu

  • Display Alternative Account in Additional Data screen of FB03

    Dear SAP experts,
    Transaction code FB03's screen does have an alternative account column. But I want to display
    Alternative account when I click on each account (in line item of FB03 screen) or display
    alternative account in Additional Data screen of FB03. I don't know how to do it.
    Does anyone here know about configuring this, please help me.
    Thank you so much.
    Maxielight.

    Hi,
    To display the "Alternative Account Number" field in report of the new General Ledger, please proceed as follows:
    1) Implement Note 895609 and 939649.
    2) To display "Alternative Account Number" in the line layout variant, proceed as follows:
    - Call transaction O7R3 and add BSEG-LOKKT as special field.
    - Then change the line layout variant. The system now displays the "Alternative Account Number" field.
    3) In the line item display in the classic General Ledger (transaction FBL3N), you could enhance the custom selections in transaction SE36 as described in Note 310886. However, in the new General Ledger, the custom selection in transaction FAGLL03 has different sub-areas. Each of these areas corresponds to a structure:
    G/L account master record SKA1_FS
    G/L account company code SKB1_FS
    G/L account line item BSIS_FS
    Since the "Alternative Account Number" is not included in the structure SKB1_FS in the standard delivery, please implement the enhancement as described in Note 945932.  To include more fields in the custom selections of transaction FAGLL03, you can enhance the structures using an APPEND.
    Regards,
    Gaurav

  • Classification System for Vendor Master Data

    Can we create Vendor classed as we do for Material Master?

    Hi
    Yes we can do that.
    First create class in CL01 or CL02. class type for vendors is 010.
    Now goto CL24N, enter class and class type. Click on new assignments.
    system will ask you object type. class or vendor. Choose vendor and press enter.
    Enter vendor numbers and save.
    Now goto display or change vendor master data.
    In Menu, click on Environment> classification. automatically class is assigned to vendor

  • Convert util.Date to sql.Date with time being displayed!

    Hi all,
    I want to convert util.Date to sql.Date for passing the same to Database. (i donot want to use Timstamp, for some reasons)
    java.sql.Date sqldate =
    new java.sql.Date(new java.util.Date().getTime());
    This simple code truncates the Time component and the result will be only Date. But my requirement is for Data and Time, both.
    Request anyone to suggest how to go abt this problem.
    Thanx.

    You can use the class java.text.DateFormat (java.text.SimpleDateFormat) for displaying. For example like this.
    java.sql.Date sqldate = new java.sql.Date(new java.util.Date().getTime());
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
    String str = formatter.format(sqldate);
    System.out.println(str);

  • Can we display Cube update time and date

    Hi All,
    can we display Cube refresh time and date for user with out going into the Cube properties. Can we use any substitution variable for that?
    Another doubt----
    Will there be any systen defined default substitution variable in Essbase or anly user defined variables. IF there what are they and purpose of it?
    Regards

    After the successful cube building, you can capture the time stamp from the system into a variable and you can set the note on database.
    suppose below is the maxl script updatetime.mxl
    login $1 identified by $2 on $3 ;
    spool on to $4 ;
    alter database $5.$6 set note $7 ;
    logout ;
    spool off ;
    exit ;
    you can call the script like
    essmsh updatetime.mxl <<userid>> <<pwd>> <<server>> <<spoolfile>> <<appname>> <<dbname>> <<updatetime>>

  • 'Latest Start Date' & 'Effective Start Date' are displayed as different

    Issue Background:
    I have told following steps to follow while creating an employee to my end users.
    Case: An employee record has to be entered on 02-05-2012 who joined on 01-01-2010.
    Steps to be followed:
    - Enter the basic details of the employee (on 'People' form) / Left the 'Effective Start Date' and 'Latest Start Date' as default date i.e. 02-05-2012
    - Ctrl + S
    - Click on 'Assignment' button
    - Enter Basic Assignment information (The effective date on Assignment form is being displayed as '02-05-2012')
    - Ctrl + S / Close the assignment form
    - Change the 'Latest Start Date' = 01-01-2010
    - Ctrl + S / Some warnings appear and then the record is saved.
    My end user created at least 100 employees following the same procedure.
    Issue:
    With at least 5 employees there is a case that when I query those employees I am able to see a different Effective Start Date (i.e. 01-01-2010) and Latest Start Date (i.e. 02-05-2012). And when I open the assignment form the effective date displayed there is '02-05-2012' as well. ....Means some how in these records the assignment is created for these employees starting from 02-05-2012..rather than 01-01-2010.
    When I try to change the Latest Start Date to 01-01-2010 then system shows me this error --> '_APP-PAY-06841: Person changes exist between the old date and new date._'
    I don't know EITHER how this case was produced while entering the date OR what is the solution of this problem.
    Can any body help in this regard?

    Thanks for your response Avinash.
    Btw, I have viewed all these notes 368289.1, 603233.1, 399056.1, 329692.1, 1146414.1 already, but these don't seem to solve my problem because in each of these are under assumption that the initial Joining Date of the employee (i.e. Effective Start Date and Latest Start Date) is entered correctly without an issue, and these notes talk about dealing with 'Updating or Correcting' the data.
    But In my case the pre-conditions are different, although those are making the system to respond in the same way (i.e. showing same error) some how.
    As far as deleting the employees is concerned, yes that could be one option, but I am not really sure about adapting this solution as the dates I used in my case were just example dates, and in actual these employees are created almost 1 month back and they are already used in Projects module, CRM module and others.

  • Not able to change the data of test data containers in production system

    Dear All,
    We have created eCATT scripts in Development SolMan System and moved the transports to Production SolMan System.  Customer wants to change the data at Test data containers and run the scripts in production system but we are not able to edit the data. 
    May be the reason is SCC4 transaction code has set the below option.
    Changes and transports for client-specific Objects
    u2022 No changes allowed
    Customer doesnu2019t want to change the above option and wanted to change the test data containers to give different datau2019s and run the eCATT scripts.
    Could you please let me know the solution for this?
    Your help is really appreciated.
    Thanks,
    Mahendra

    eCatt has the feature where you don't need to transport the scripts or test configuration to our target system. We can keep all our scripts and test data in Solman and run this script any other system in your landscape using the System data container and target system.
    Maintain the production as one of the target system in System container in Solman and point that system while running the script. Change the test data in Solman to run this script.
    Let me know if you need more information
    thanks
    Venkat

  • Custom fields not display in SRM5.5 Basic Data Frame

    Hello Everybody,
          I am working on SRM5.5 Server which i have to add two custom fields in Basic Data Frame..
         No field is display in basic data frame After I added those fields in INCL_EEW_PD_ITEM_CSF_SC and INCL_EEW_PD_ITEM_CSF.
        I added these fields by help of 672960 OSS notes..
       Add also when i execute the program BBP_DYNPROS_GENERATE where I entered the program name as SAPLBBP_PDH_CUF and execute but non of them is working fine..
      Is there anything else do i need to display custom fields in basic data frame??
    I have one more question..
      When you logon through SAPGUI and goto BBPSC01 t.code where you see lots of fields in basic data frame such as unloading point and all.. But those all fields does not display when you logon through WebURL..
      I checked is there any BAdi such CUF or Screenvarient or some Badi has been actived but non of the Badi has been implemented..
      To display all the fields which are display in GUI Mode also should display in URL..
      To bring this functionality , What do i need to do?
      I appreciate if you answer these questions..
    Thanks,
    John.

    Hi Disha,
    We are trying to add custom fields to the Shopping Cart Header. We are using SRM 5.0. We added the fields to the structures "INCL_EEW_PD_HEADER_CSF_SC" & "INCL_EEW_PD_HEADER_CSF".  We are able to see the custom fields. But the issue is , we are able to see the custom fields in the Shopping Cart one step shop scenario. Whereas when we run the wizard which is a 3 step scenario, we are not able to see the custom fields.
    Technically speaking, the custom fields are visible for the ITS BBPSC01 & BBPSC03 , where as these custom fields are not visible for the ITS BBPSC02.
    Please let me know, if we need to append the fields to some other structure to be able to see them in the Shopping cart wizard also.
    I will be gald to provide any kind of info.
    Thanks in advance...

  • How do I have photos in iPhoto display on their face the date and time?

    How do I have photos in iPhoto display on their face the date and time? Displaying in the camera shows this. When I check edit the info is there. How do I have that displayed on the face of the photo when I view it in iPhoto?

    How do I have photos in iPhoto display on their face
    the date and time? Displaying in the camera shows
    this. When I check edit the info is there. How do I
    have that displayed on the face of the photo when I
    view it in iPhoto?
    Hi! My name is Tom from San Diego, CA. I have the exact same question as you. That is, I would like to be able to print out a photo from iphoto with the date that picture was taken displayed on the face of it. In this way, someone looking at that picture in a photo album years later would know when it was taken. Did you ever find a method to print copies of photos out of iphoto with the date displayed on the print? Thanks for your help!

  • Creation of master data info object- data coming form a 3rd party system

    Hi All
    i need to create a master data info - object  which connects the customer and the corresponding plant..actually thios data is coming from a third party system and they have maintained 2 tables one for customer and one for the plant details and these 2 tables are connected through some common id which populates unquie id for each customer and is maintained in the plant table with the same id...now both these tables have to be merged together and to be cretaed as a single info object..can any one suggest  me as to how to proceed with it.
    Regards
    Shilpa

    Hi,
    Create a Z-InfoObject with the same format as is used in your 3rd party system for the commonid.
    Add Customer and Plant as navigational Attributes.
    Create an infosource with these three fields.
    Unload (in a CSV-file) the commonid with customer and plant from your 3rd party system.
    Load these data to BI into your newly created Z-commonid InfoObject.
    Success,
    Udo

  • The operating system returned error 23(Data error (cyclic redundancy check).)

    My Stored Procedures and Jobs Showing this Error. Even though i can able to access the data throgh SSMS in Database Engine.Please help on this.
    Executed as user: RMS\Administrator. The operating system returned error 23(Data error (cyclic redundancy check).) to SQL Server during a read at offset 0x000006684a2000 in file 'F:\RMSLiveData\RMS.mdf'. Additional messages in the SQL Server error log and
    system event log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors;
    for more information, see SQL Server Books Online. [SQLSTATE HY000] (Error 823).  The step failed.
    Thanks 
    RehaanKhan. M

    DBCCCHECKDB('DBNAME',REPAIR_ALLOW_DATA_LOSS)
    For crying out loud! Don't you have any shame!
    There are situations where you may have to run DBCC CHECKDB with the option REPAIR_ALLOW_DATA_LOSS, but it is not the first thing you shold try if the database seems to be corrupt. Particularly, you should first make sure that you work on a copy of the database
    files. REPAIR_ALLOW_DATA_LOSS means that DBCC CHECKDB has carte blanche to throw all pages it can piece together - which could be about all data pages if it is that bad.
    Corruption siuations are very difficult to assist with in forums, because there can be a lot of stake. The only advice I can give is to restore the database from a clean backup. If you don't have a clean backup, you have a problem. The database may still
    be saved, but you need an expert on site to help you, if you have never worked with this before. Advice given in this forum applied haphazardly can result in more damage that you already have.
    But, oh, one thing: this type of corruption are always due to hardware errors like bad disks or bad memory sticks. So just restoring the database is not enough. Finding new hardware is important too.
    Erland Sommarskog, SQL Server MVP, [email protected]
    Actually on the same disk there are other Databases Stored and they work Properly and Backup also can be taken for that Databases. But, for this particular database only this error is happening when iam trying to take backup. But data retrieval and access to
    front end application happening as usual.  Please help on this.
    RehaanKhan. M

  • HT201250 I had to replace the hard drive in my old MacBook. I replaced it. Installed OSX10.6. Then using the system software I reinstalled data from my Time Machine backup. On completion it asked for my password. It is not accepted. I am locked out how I

    I had to replace the hard drive in my old MacBook. I replaced it. Installed OSX10.6. Then using the system software I reinstalled data from my Time Machine backup. On completion it asked for my password. It is not accepted. I am locked out how I overcome this?
    I was already using 10.7. But only had the disc for 10.6.

    Sorry I am new to this. Am I in the right area? I am using my iPhone to make contact. I am worried.

Maybe you are looking for