none
Linq Display data from Multiple Columns into a 1 Column Row Wise RRS feed

  • Question

  • Hi,

    I'm working on a Windows Phone 7 Application and for Database access Ive to use Linq to SQL with a WCF Service app.

    To Display the data from the database into a Listbox Im using a Stackpanel with <textblock text= "{Binding Colname}"

    This is the layout of my Table:

    http://f.cl.ly/items/3Q1X0t382H0C46011g2k/BESTtable.jpg

    This is the Linq query Im currently using to get the data using a where condition:

     

     public List<ORD_BUS> FindFare(int BUS_NO)
            {

                DataClasses1DataContext context3 = new DataClasses1DataContext();


                var res1 = from r in context3.ORD_BUS where r.BUS_NO == BUS_NO select r;
                return res1.ToList();

             }

     

    Now the result of this query would be like with multiple columns. 

    I can use the StackPanel to display them in a row by using this code:

     

     <ListBox Height="194" HorizontalAlignment="Left" Margin="210,214,0,0" Name="listBox3" VerticalAlignment="Top" Width="176" >
    
        <ListBox.ItemTemplate>
    
        <DataTemplate>
    
         <StackPanel Orientation="Vertical">
    
         <TextBlock Text="{Binding SOURCE1}"/>
         <TextBlock Text="{Binding SOURCE2}"/>
         <TextBlock Text="{Binding SOURCE3}"/>
         <TextBlock Text="{Binding SOURCE4}"/>
         <TextBlock Text="{Binding SOURCE5}"/>
         <TextBlock Text="{Binding SOURCE6}"/>
         <TextBlock Text="{Binding SOURCE7}"/>
         <TextBlock Text="{Binding SOURCE8}"/>
         <TextBlock Text="{Binding SOURCE9}"/>
         <TextBlock Text="{Binding SOURCE10}"/>
         <TextBlock Text="{Binding SOURCE11}"/>
         <TextBlock Text="{Binding SOURCE12}"/>
         <TextBlock Text="{Binding SOURCE13}"/>
         <TextBlock Text="{Binding SOURCE14}"/>
         <TextBlock Text="{Binding SOURCE15}"/>
         <TextBlock Text="{Binding SOURCE16}"/>
    
    
    
         </StackPanel>
    
        </DataTemplate>
    
        </ListBox.ItemTemplate>
    
       </ListBox>

     

    But since the actual data is in Multiple Columns format when I try to select any 1 Source from the Listbox the entire contents get selected.

    So I suppose the only way to select 1 item at a time would be to get the multiple column values in just 1 Column and display them as multiple rows.

    Any suggestions?

     

     

    • Edited by Tanmay® Sunday, February 13, 2011 6:58 AM Code Edit
    Sunday, February 13, 2011 6:38 AM

Answers

All replies

  • Hi Tanmay,

    Thanks for your post.

    Your question may not really relates to LINQ to SQL,  A ListBox control can provide single or multiple selections using the SelectionMode property. The ListBox also provides the MultiColumn property to enable the display of items in columns instead of a straight vertical list of items. With this, the control can display more visible items and the user no longer needs to scroll to an item

    You can refer here: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 14, 2011 6:29 AM
    Moderator
  • Oh that seems so silly of me! I'll try this asap and if it works will marks your reply as answer :) Thanks man!
    Monday, February 14, 2011 3:47 PM
  • Hi Tanmay,

     I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 17, 2011 2:36 AM
    Moderator
  • Hi Alan_chen... can you help me .. in my process ,,.. i am confused in one page ... if u agree to help me please give ur meil i will ask question Rply here..

    New born in developing

    Sunday, June 10, 2012 10:05 AM