Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if ((dt.Rows.Count > 0))
    {
        for (i = 0; i <= dt.Rows.Count - 1; i++)
        {
            string[] s = dt.Rows[i]["Working_Year"].ToString().Split(new char[] { '_' });
            string[] a = s[0].Split(new char[] { '-' });
            string[] b = s[2].Split(new char[] { '-' });
            Variables.StartDate1 = a[0] + "/" + a[1] + "/" + a[2];
            Variables.EndDate1 = b[0] + "/" + b[1] + "/" + b[2];

            string dat = a[0].ToString() + "-" + common_function.GetMonth(int.Parse(a[1].ToString())) + "-" + a[2].ToString();
            string dat2 = b[0].ToString() + "-" + common_function.GetMonth(int.Parse(b[1].ToString())) + "-" + b[2].ToString();
            DataRow newRow = data.NewRow();
            newRow["Company ID"] = dt.Rows[i]["Compid"].ToString();
            newRow["Company Name"] = dt.Rows[i]["CompanyName"].ToString();
            newRow["Working_Year"] = dat.ToString() + "  -  " + dat2.ToString();
            data.Rows.Add(newRow);
        }
    }
    dataGrid_selectCompany.ItemsSource = data;
    dataGrid_selectCompany.DataContext = data;
    dataGrid_selectCompany.Columns(2).Width = 150;
    dataGrid_selectCompany.Columns(3).Width = 150;
}



Here is xamal code ...........

<UserControl x:Class="Manawat_WPF.Master_Form.SelectCompanyxaml"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500" Loaded="UserControl_Loaded">
    <Grid>
        <DataGrid AutoGenerateColumns="False" Height="248" HorizontalAlignment="Left" Margin="0,52,0,0" Name="dataGrid_selectCompany" VerticalAlignment="Top" Width="500" SelectionChanged="dataGrid_selectCompany_SelectionChanged">
            <DataGrid.Columns>
                <DataGridHyperlinkColumn Header="Select" />
            </DataGrid.Columns>
        </DataGrid>
        <Label Content="Select Company" Height="28" HorizontalAlignment="Center" Margin="162,12,206,0" Name="lbl_selectComapny" VerticalAlignment="Top" Width="132" />
    </Grid>
</UserControl>
Posted
Updated 17-Apr-13 1:20am
v2
Comments
Pheonyx 17-Apr-13 7:10am    
can you show your XAML for the datagrid please.
Meharwan Singh 17-Apr-13 7:13am    
here below is my Xaml Code . I wanaa bind data dynamically from code behind
<usercontrol x:class="Manawat_WPF.Master_Form.SelectCompanyxaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="500" loaded="UserControl_Loaded">
<grid>
<datagrid autogeneratecolumns="False" height="248" horizontalalignment="Left" margin="0,52,0,0" name="dataGrid_selectCompany" verticalalignment="Top" width="500" selectionchanged="dataGrid_selectCompany_SelectionChanged">
<datagrid.columns>
<datagridhyperlinkcolumn header="Select">


<Label Content="Select Company" Height="28" HorizontalAlignment="Center" Margin="162,12,206,0" Name="lbl_selectComapny" VerticalAlignment="Top" Width="132" />

Meharwan Singh 17-Apr-13 7:16am    
<usercontrol x:class="Manawat_WPF.Master_Form.SelectCompanyxaml"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="500" loaded="UserControl_Loaded">
<grid>
<datagrid autogeneratecolumns="False" height="248" horizontalalignment="Left" margin="0,52,0,0" name="dataGrid_selectCompany" verticalalignment="Top" width="500" selectionchanged="dataGrid_selectCompany_SelectionChanged">
<datagrid.columns>
<datagridhyperlinkcolumn header="Select">


<Label Content="Select Company" Height="28" HorizontalAlignment="Center" Margin="162,12,206,0" Name="lbl_selectComapny" VerticalAlignment="Top" Width="132" />

Pheonyx 17-Apr-13 7:17am    
The only Xaml I can see in what you pasted is the label.
Can you use "Improve question" and past it there using the code formatters"

I would expect to see your <datagrid x:datagrid_selectcompany=""> control in it.

1 solution

try adding:

XML
<datagridtextcolumn header="Year" binding="{Binding Working_Year}" />


into your XAML and see if anything starts displaying.
I have a feeling the binding is working, however because you have not configured any columns to bind to it you are not seeing anything.

Especially as you have set this: AutoGenerateColumns="False"
 
Share this answer
 
v2
Comments
Meharwan Singh 17-Apr-13 7:29am    
issue is that there if i am trying to data table bind to the data grid then i am getting error of casting bcz type conversion is not matched so please suggest me
Pheonyx 17-Apr-13 7:38am    
what is the exact error, copy and paste it.
Also, at what point does the error occur? Step through the code and identify which line it is.

What object type is 'data'?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900