How to add text to the GridView in wpf?
-
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
-
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
-
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;
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
-
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
You have misunderstood what I said. Assign the LIST of MESSAGE to the DataContext. e.g.,
lstViewLogWindow.DataContext = yourListOfMessages;
where
yourListOfMessages
is something like 'List<YourMessageType>
' andYourMessageType
is a type having Message_Name andDateTime
property -
You have misunderstood what I said. Assign the LIST of MESSAGE to the DataContext. e.g.,
lstViewLogWindow.DataContext = yourListOfMessages;
where
yourListOfMessages
is something like 'List<YourMessageType>
' andYourMessageType
is a type having Message_Name andDateTime
propertysorry.. 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
-
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
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;
-
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;
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<string> 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