Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:24:56+00:00 2026-05-24T04:24:56+00:00

I have a grid view code below which have divided into 3 column .

  • 0

I have a grid view code below which have divided into 3 column.
But i have a problem with the code is that.
When multiple data is retrieved.
All the data in the 3 column is overlapping.
How can i modify the below code such as it will show one after another below it.

           //Define grid column, size

            Grid schedule = new Grid();

            foreach (var time in timeSplit)
            {
                timeList = time;
                //Column 1 to hold the time of the schedule
                ColumnDefinition scheduleTimeColumn = new ColumnDefinition();
                GridLength timeGrid = new GridLength(110);
                scheduleTimeColumn.Width = timeGrid;
                schedule.ColumnDefinitions.Add(scheduleTimeColumn);

                //Text block that show the time of the schedule
                TextBlock timeTxtBlock = new TextBlock();
                timeTxtBlock.Text = time;
                //Set the alarm label text block properties - margin, fontsize
                timeTxtBlock.FontSize = 28;
                timeTxtBlock.Margin = new Thickness(0, 20, 0, 0);
                //Set the column that will hold the time of the schedule
                Grid.SetColumn(timeTxtBlock, 0);

                schedule.Children.Add(timeTxtBlock);
            }

            foreach (var title in titleSplit)
            {
                titleList = title;

                //Column 2 to hold the title of the schedule
                ColumnDefinition scheduleTitleColumn = new ColumnDefinition();
                GridLength titleGrid = new GridLength(500);
                scheduleTitleColumn.Width = titleGrid;
                schedule.ColumnDefinitions.Add(scheduleTitleColumn);

                //Text block that show the title of the schedule
                TextBlock titleTxtBlock = new TextBlock();

                if (title.Length > 10)
                {
                    string strTitle = title.Substring(0, 10) + "....";
                    titleTxtBlock.Text = strTitle;
                }
                else
                {
                    titleTxtBlock.Text = title;
                }

                //Set the alarm label text block properties - margin, fontsize
                titleTxtBlock.FontSize = 28;
                titleTxtBlock.Margin = new Thickness(60, 20, 0, 0);
                //Set the column that will hold the title of the schedule
                Grid.SetColumn(titleTxtBlock, 1);

                schedule.Children.Add(titleTxtBlock);
                //scheduleListBox.Items.Add(schedule);
            }

            foreach (var category in categorySplit)
            {
                categoryList = category;

                //Column 3 to hold the image category of the schedule
                ColumnDefinition categoryImageColumn = new ColumnDefinition();
                GridLength catImgnGrid = new GridLength(70);
                categoryImageColumn.Width = catImgnGrid;
                schedule.ColumnDefinitions.Add(categoryImageColumn);

                TextBlock categoryTxtBlock = new TextBlock();
                categoryTxtBlock.Text = category;

                //set the category image and its properties - margin, width, height, name, background, font size
                Image categoryImage = new Image();
                categoryImage.Margin = new Thickness(-50, 15, 0, 0);
                categoryImage.Width = 50;
                categoryImage.Height = 50;
                if (category == "Priority")
                {
                    categoryImage.Source = new BitmapImage(new Uri("/AlarmClock;component/Images/exclamination_mark.png", UriKind.Relative));
                }
                else
                    if (category == "Favourite")
                    {
                        categoryImage.Source = new BitmapImage(new Uri("/AlarmClock;component/Images/star_full.png", UriKind.Relative));
                    }


                Grid.SetColumn(categoryImage, 2);
                schedule.Children.Add(categoryImage);
            }

            scheduleListBox.Items.Add(schedule);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:24:57+00:00Added an answer on May 24, 2026 at 4:24 am

    Quickhorn’s answer is mostly right. The issue is you’re creating one big grid instead of a row for each item in the list. Here’s a simplified example of your code which uses a model object and databinding instead.

    This way you can style everything in the xaml easily and it makes things much simpler.

    Code Behind: MainPage.xaml.cs

    public partial class MainPage : PhoneApplicationPage
    {
        private ObservableCollection<Schedule> _schedules;
    
        public MainPage()
        {
            InitializeComponent();
    
            string[] timeSplit = new string[] { "One1", "Two2", "Three3" };
            string[] titleSplit = new string[] { "Title1", "Title2", "Title3" };
            string[] categorySplit = new string[] { "Priority", "Favourite", "Another" };
    
            _schedules = new ObservableCollection<Schedule>();
    
            for ( int i = 0; i < timeSplit.Length; i++ )
            {
                _schedules.Add( CreateSchedule( timeSplit[i], titleSplit[i], categorySplit[i] ) );
            }
    
            scheduleListBox.ItemsSource = _schedules;
        }
    
        private Schedule CreateSchedule( string time, string title, string category )
        {
            Schedule schedule = new Schedule
            {
                Time = time,
                Title = title,
                Category = category
            };
    
            if ( category == "Priority" )
            {
                schedule.ImageSource = "/AlarmClock;component/Images/exclamination_mark.png";
            }
            else if ( category == "Favourite" )
            {
                schedule.ImageSource = "/AlarmClock;component/Images/star_full.png";
            }
    
            return schedule;
        }
    }
    
    public class Schedule
    {
        public string Time { get; set; }
        public string Title { get; set; }
        public string Category { get; set; }
        public string ImageSource { get; set; }
    }
    

    MainPage.xaml

    <ListBox
        x:Name="scheduleListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock
                        Text="{Binding Time}"/>
                    <TextBlock
                        Text="{Binding Title}"
                        Grid.Column="1"/>
                    <StackPanel
                        Orientation="Horizontal"
                        Grid.Column="2">
                        <TextBlock
                            Text="{Binding Category}"/>
                        <Image
                            Source="{Binding ImageSource}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing an ASP.net c# application. I have a grid view which
I have the below code in my jqgrid <script type=text/javascript> jQuery(document).ready(function() { var grid
I am using grid view with ImageAdapter to display images. I have two set
I have project on recruitment.In this project, at one form I have a grid
I created a wpf application which have a single window which is getting started
i have datasource which has an sp called for update and been binded to
I have two aspx files for adding/deleting products to/from a sale. islemler.aspx SatisTedarik.aspx I
I've got a gridview that populates from four tables, and the select command (shown
I have a TextBox in the TemplateField of a GridView. And I have one
OK...I've spent too much time floundering on this one, so I'm passing it on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.