locked
how to add table RRS feed

  • Question

  • how to add a table .

    private void btnarray_Click(object sender, RoutedEventArgs e)
            {
                int limit = int.Parse(txtlimit.Text);
                try
                {
                    // assigning textbox into string 
                    string num1split = txtnum1.Text;
                    string num2split = txtnum2.Text;
                    
                    // reading space via
                    string[] split1 = num1split.Split(new Char[] { ' ' });
                    string[] split2 = num2split.Split(new Char[] { ' ' });
    
                    // assigning intger array to string array
                    int[] num1 = new int[split1.Length];
                    int[] num2 = new int[split2.Length];
    
                    // converting string arrary to intger array
                    int convert1 = 0, convert2 = 0;
                    foreach (String text1 in split1)
                    {
                        int.TryParse(text1, out num1[convert1]);
                        ++convert1;
                    }
                    foreach (String text2 in split2)
                    {
                        int.TryParse(text2, out num2[convert2]);
                        ++convert2;
                    }
                    // adding two array
                    int[] result = new int[limit];
                    for (int i1 = 0, j1 = 0; i1 < num1.Length; i1++, j1++)
                    {
                        result[i1] = num1[i1] + num2[j1];
                    }
                    // displaying array elements
                    txtresult.Text = string.Join(" ",num1) + "\r\n";
                    txtresult.Text += string.Join(" ",num2) + "\r\n";
                    foreach (int s in result)
                    {
                        txtresult.Text += +s +" ";
                    }
                    foreach (int s in result)
                    {
                        lstdisplay.Items.Add("Sum "+ s.ToString());
                    }
                }

    i want to my output in table (how to add column  inside the list box or list view)

    and this  two type


    • Edited by luna_luna Friday, December 20, 2013 12:50 PM
    Friday, December 20, 2013 12:47 PM

Answers

  • Hi,

    In windows store app, you can create a ItemTemplate in GridView or Listview to make the items to display in columns.

    See some codes below:

    XAML:

     <GridView ItemsSource="{Binding }" Name="gridview">
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" Width="600"></StackPanel>
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200"></ColumnDefinition>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{Binding Date}"></TextBlock>
                            <TextBlock Grid.Column="1" Text="{Binding City}"></TextBlock>
                            <TextBlock Grid.Column="2" Text="{Binding Count}"></TextBlock>
                            <TextBlock Grid.Column="3" Text="{Binding ICount}"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>

    Code-Behind:

     public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
                List<Test> test = new List<Test>();
                test.Add(new Test { Date = new DateTime(2013, 1, 1), City = "NewYork", Count = 30, ICount = 12 });
                test.Add(new Test { Date = new DateTime(2013, 1, 2), City = "NewYork", Count = 31, ICount = 13 });
                test.Add(new Test { Date = new DateTime(2013, 1, 3), City = "NewYork", Count = 32, ICount = 14 });
                test.Add(new Test { Date = new DateTime(2013, 1, 4), City = "NewYork", Count = 33, ICount = 15 });
                test.Add(new Test { Date = new DateTime(2013, 1, 5), City = "NewYork", Count = 34, ICount = 16 });
                test.Add(new Test { Date = new DateTime(2013, 1, 6), City = "NewYork", Count = 35, ICount = 17 });
                gridview.DataContext = test;
            }
        }
        public class Test
        {
           public DateTime Date { get; set; }
           public string City { get; set; }
           public int Count { get; set; }
           public int ICount { get; set; }
        }
    }

    And also, Telerik provides a data grid control for windows 8 store apps.

    here's the link: http://www.telerik.com/products/windows-8/controls/grid.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Monday, December 30, 2013 7:19 AM
    Monday, December 23, 2013 2:26 AM