Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to add text to the GridView in wpf?

How to add text to the GridView in wpf?

Scheduled Pinned Locked Moved WPF
wpfcsharpcsswcfdesign
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krishna Aditya
    wrote on last edited by
    #1

    Hi, I am developing an UI app, in WPF, for the Log window, I have xaml code <ListView x:Name="lstViewLogWindow" ItemsSource="{Binding}" Height="152"> <ListView.View> <GridView> <GridViewColumn Header="Message_Name" Width="Auto" DisplayMemberBinding="{Binding Path= Message_Name}" /> <GridViewColumn Header="DateTime" Width="Auto" DisplayMemberBinding="{Binding Path= DateTime}" /> </GridView> </ListView.View> </ListView> So, I have a grid view with 2 headers Message_Name and DateTime, and I want to assign the data to the 2 columns... I am not able to get the data displayed by using lstViewLogWindow.Items.Add(msg); Actually I want to add some msg into First col and date time into second column, Please help me in doing this. Thanks Ramm

    A 1 Reply Last reply
    0
    • K Krishna Aditya

      Hi, I am developing an UI app, in WPF, for the Log window, I have xaml code <ListView x:Name="lstViewLogWindow" ItemsSource="{Binding}" Height="152"> <ListView.View> <GridView> <GridViewColumn Header="Message_Name" Width="Auto" DisplayMemberBinding="{Binding Path= Message_Name}" /> <GridViewColumn Header="DateTime" Width="Auto" DisplayMemberBinding="{Binding Path= DateTime}" /> </GridView> </ListView.View> </ListView> So, I have a grid view with 2 headers Message_Name and DateTime, and I want to assign the data to the 2 columns... I am not able to get the data displayed by using lstViewLogWindow.Items.Add(msg); Actually I want to add some msg into First col and date time into second column, Please help me in doing this. Thanks Ramm

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      By adding the item explicitly you are overriding the binding mechanism. You should do it by binding. Assign ListView's DataContext with the list of messages.Something like this,

      lstViewLogWindow.DataContext = yourListOfMessages;

      K 1 Reply Last reply
      0
      • A ABitSmart

        By adding the item explicitly you are overriding the binding mechanism. You should do it by binding. Assign ListView's DataContext with the list of messages.Something like this,

        lstViewLogWindow.DataContext = yourListOfMessages;

        K Offline
        K Offline
        Krishna Aditya
        wrote on last edited by
        #3

        Ya.. But its not displaying the text in 2 columns/. I added DataContext..                   lstViewLogWindow.DataContext = lstViewLogWindow.Items.Add(DateTime.Now); how to add this to a particular header like DateTime <pre>         <GridView>                                                                                                             <GridViewColumn Header="Message Name" Width="Auto" DisplayMemberBinding="{Binding Path= Message_Name}" />                                     <GridViewColumn Header="DateTime" Width="Auto" DisplayMemberBinding="{Binding Path= DateTime}" />                               </GridView></pre> Pleaes help Thanks Ramm

        A 1 Reply Last reply
        0
        • K Krishna Aditya

          Ya.. But its not displaying the text in 2 columns/. I added DataContext..                   lstViewLogWindow.DataContext = lstViewLogWindow.Items.Add(DateTime.Now); how to add this to a particular header like DateTime <pre>         <GridView>                                                                                                             <GridViewColumn Header="Message Name" Width="Auto" DisplayMemberBinding="{Binding Path= Message_Name}" />                                     <GridViewColumn Header="DateTime" Width="Auto" DisplayMemberBinding="{Binding Path= DateTime}" />                               </GridView></pre> Pleaes help Thanks Ramm

          A Offline
          A Offline
          ABitSmart
          wrote on last edited by
          #4

          You have misunderstood what I said. Assign the LIST of MESSAGE to the DataContext. e.g.,

          lstViewLogWindow.DataContext = yourListOfMessages;

          where yourListOfMessagesis something like 'List<YourMessageType>' and YourMessageTypeis a type having Message_Name and DateTime property

          K 1 Reply Last reply
          0
          • A ABitSmart

            You have misunderstood what I said. Assign the LIST of MESSAGE to the DataContext. e.g.,

            lstViewLogWindow.DataContext = yourListOfMessages;

            where yourListOfMessagesis something like 'List<YourMessageType>' and YourMessageTypeis a type having Message_Name and DateTime property

            K Offline
            K Offline
            Krishna Aditya
            wrote on last edited by
            #5

            sorry.. really I couldnt get u.. actually as I have 2 columns Message Name and Datetime in my design, yourListOfMessages will be   1. _eventAggregator.GetEvent<StatusBarMsgShowEvent>().Publish("Click on Save to save the Log window Details"); ------------ to be assigned to column1 2 . DateTime.now   ----------- to be assigned to column2... I think I am not getting you wat U said.. but I am expecting this.. in my logwindow --------------------------------------------------------------------------------- Message                                                               DateTime Click on Save to save the Log window Details      09/08/2009 12:15:20AM -------------------------------------------------------------------------------- Thank you, Ramm

            A 1 Reply Last reply
            0
            • K Krishna Aditya

              sorry.. really I couldnt get u.. actually as I have 2 columns Message Name and Datetime in my design, yourListOfMessages will be   1. _eventAggregator.GetEvent<StatusBarMsgShowEvent>().Publish("Click on Save to save the Log window Details"); ------------ to be assigned to column1 2 . DateTime.now   ----------- to be assigned to column2... I think I am not getting you wat U said.. but I am expecting this.. in my logwindow --------------------------------------------------------------------------------- Message                                                               DateTime Click on Save to save the Log window Details      09/08/2009 12:15:20AM -------------------------------------------------------------------------------- Thank you, Ramm

              A Offline
              A Offline
              ABitSmart
              wrote on last edited by
              #6

              This is my best attempt.

              public class LogMessage
              {
              public string Message_Name { get; set; }
              public DateTime LogTime { get; set; }
              }

              Then you have your list of messages like this,

              List<LogMessage> messages = new List<LogMessage>();
              messages.Add(new LogMessage(){Message_Name = "Dummy Message", LogTime = DateTime.Now});

              lstViewLogWindow.DataContext = messages;

              K 1 Reply Last reply
              0
              • A ABitSmart

                This is my best attempt.

                public class LogMessage
                {
                public string Message_Name { get; set; }
                public DateTime LogTime { get; set; }
                }

                Then you have your list of messages like this,

                List<LogMessage> messages = new List<LogMessage>();
                messages.Add(new LogMessage(){Message_Name = "Dummy Message", LogTime = DateTime.Now});

                lstViewLogWindow.DataContext = messages;

                K Offline
                K Offline
                Krishna Aditya
                wrote on last edited by
                #7

                HI.. Thanks for the help. But I am doing this using subscribe and publish.. public class LogWindowMsgShowEvent : CompositePresentationEvent<string>       {       }                   _eventAggregator.GetEvent<LogWindowMsgShowEvent>().Subscribe(this.ShowMessage);                _eventAggr.GetEvent<StatusBarMsgShowEvent>().Publish("Database Connection Error"); so, in CompositePresentationEvent&lt;string&gt; I can see a string here.. do I need to add the class Logwindow to the CompostePresentationEvent?? Actually both the CompositePresentationEvent and the presenter it accesses are in diff modules... HOw to handle this/ Please help Thanks Ramm

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups