|
Hi, i tried this code to parse CSV file and save data in a wpf data grid, the code is correct but i can't store values on datagrid
this is a class wich contain the code:
public class CsvParser
{
public List<string[]> ReadAndParseData(string path, char separator)
{
var parseData = new List<string[]>();
using (var sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] row = line.Split(separator);
parseData.Add(row);
}
}
return parseData;
}
}
}
the is the code behind; assigned to event click on boutton
List<string[]> parseData = csv.ReadAndParseData(datasource, ';');
foreach (string[] row in parseData)
{
MessageBox.Show(""+row.GetValue(0));// i get the correct value
dgvreceipient.Items.Add(row.....);// but i get a empty datagrid
}
|
|
|
|
|
Why do you persist in trying to do this the wrong way? You could solve this simply with an ObservableCollection and a little bit of binding.
public class CsvReaderViewModel
{
public ObservableCollection<string> CsvLines { get; set; }
public CsvReaderViewModel(string datasource)
{
List<string> csv = new CsvParser().ReadAndParseData(datasource, ';');
CsvLines = new CsvLines(csv);
}
} Then, "in your code behind", all you need do is (make sure you have called InitializeComponent before you try this):
CsvReaderViewModel vm = new CsvReaderViewModel("my source");
DataContext = vm; Finally, you just need to set your grid ItemsSource to CsvLines .
BTW - you have posted and been told often enough, format your code blocks using the pre tags. It's not hard to do.
|
|
|
|
|
thank you, tried it, but i can't debug solution when i add
CsvReaderViewModel vm = new CsvReaderViewModel("my source");
DataContext = vm;
near InitializeComponent();
|
|
|
|
|
Hi,
I'm using a DockPanel in my application and am struggling to have my buttons appear on the let side of the panel. They are all placed centrally. My XAML code is as follows
<pre lang="xml">
<ribbon:RibbonApplicationMenuItem x:Name="OpenItems" ImageSource="Images\Open.ico" Header="Open">
<DockPanel LastChildFill="True" DockPanel.Dock="Left" HorizontalAlignment="Left">
<ribbon:RibbonButton DockPanel.Dock="Top" x:Name="OpenBtn1" SmallImageSource="/WpfRibbonApplication1;component/Images/Open.ico" Label="Open" />
<ribbon:RibbonButton DockPanel.Dock="Bottom" x:Name="OpenBtn2" SmallImageSource="/WpfRibbonApplication1;component/Images/Open.ico" Label="Open Specific File" />
</DockPanel> </ribbon:RibbonApplicationMenuItem>
</pre>
I'm aiming to produde a DockPanel that looks like the Micorsoft Word, with selectable item that has Icon on the left, and then two rows of text.
Can anyone either point out where I have gone wrong and point out the error in my code, or point me to a suitable tutorial to manage the layout of my dock panel.
TIA
Tony
|
|
|
|
|
Set HorizontalAlignment="Left" on your RibbonButton elements instead.
|
|
|
|
|
Assuming this is what you are suggesting
<pre lang="xml">
<ribbon:RibbonButton HorizontalAlignment="Left" DockPanel.Dock="Top" Label="Open" />
</pre>
That doesnt work, I'm still getting the button appearing centrally.
Thanks for the reply though.
Tony
|
|
|
|
|
Sorry, I see what you're trying to do here. I ran this through Blend to get this:
<ribbon:RibbonApplicationMenuItem
x:Name="OpenItems" Header="Open" HorizontalAlignment="Left" VerticalAlignment="Top">
<DockPanel DockPanel.Dock="Left" HorizontalAlignment="Left">
<ribbon:RibbonButton DockPanel.Dock="Top" x:Name="OpenBtn1" Label="Open" HorizontalAlignment="Left" />
<ribbon:RibbonButton DockPanel.Dock="Bottom" x:Name="OpenBtn2" Label="Open Specific File" />
</DockPanel> </ribbon:RibbonApplicationMenuItem>
|
|
|
|
|
Still no joy
When using a a preview panel (from within VS2010) the panel looks fine, but in the app the items are still centred (or just left of centre to be more accurate).
I guess there must a configuration item I am missing from the ApplicationMenu and DockPanel.
Thanks
Tony
|
|
|
|
|
The problem you are seeing is not the problem you think you see. The items are being aligned properly - within the RibbonMenu - this means that you need to adjust the ItemContainerStyle to change how the menu is displayed. Basically, the padding is to put all the other button chrome such as the images, checkboxes, popup glyphs, etc into place.
|
|
|
|
|
Use HorizontalContentAlignment = True
This will arrange the content to LEFT
|
|
|
|
|
Hi all,
I am just beginning out with wpf, so sorry for what is probably an easy question! The reason for my interest in wpf is that I have an application that I need to run on several pcs with different resolutions. What I would like to do is have an area in the app with several buttons on. I want the area to be callable with several 'pages' - similar to using tabs, but I would scroll from left to right through the pages. Each page may have 10 - 20 buttons on it, which will be dynamically positioned on startup, and will resize depending on the resolution of the screen. Any suggestions on how to do this?
Thanks very much in advance
|
|
|
|
|
I think, you can make use of the layout controls to place your buttons ....
|
|
|
|
|
The best option is use third party control like Telerik, it provides professional way of scrolling, You can scroll pages like a book,
You also have option to scroll the pages like Photo Albumb which is really cool
|
|
|
|
|
Hey folks. I was wondering if anyone is thinking of upgrading to Adobe CS6 or will you be waiting or skipping the release. Some of our team members are on CS4 and some on CS5, what would you suggest we do regarding CS6. Will appreciate your advice and any experiences positive or negative you may have had with CS6
|
|
|
|
|
You should ask this in the lounge. Your question has nothing to do with WPF or Silverlight.
|
|
|
|
|
hi...
when write tcp channel in c# we add this reference (using System.Runtime.Remoting.Channels.Tcp;)...
i want ask if i want write TCP channel in wp7 what are i reference add ????
|
|
|
|
|
heba abu ghaleih22 wrote: what are i reference add ???
You will still need System.Runtime.Remoting.Channels (amongst others).
|
|
|
|
|
Hello,
I am new to WPF and am having a bit of trouble with a menu radio button item.
I have the following code snippets:
<Menu.Resources>
<ControlTemplate x:Key="Template" TargetType="{x:Type RadioButton}">
<Border Background="Transparent">
<MenuItem Header="{TemplateBinding Content}" IsCheckable="False" IsChecked="{TemplateBinding IsChecked}" IsHitTestVisible="False" Padding="2,3" HorizontalAlignment="Stretch">
</MenuItem>
</Border>
</ControlTemplate>
</Menu.Resources>
<MenuItem Header="Me">
<StackPanel>
<RadioButton Content="Foo" Template="{StaticResource Template}"/>
<RadioButton Content="Bar" Template="{StaticResource Template}"/>
<RadioButton Content="Biz" Template="{StaticResource Template}"/>
</StackPanel>
However, what ends up happening is that my check marks end up on the right side of the vertical menu separator as opposed to the left, as would happen normally using the IsChecked property.
Does anyone know a way to make these check marks appear to the LEFT of the vertical separator? All help is greatly appreciated.
|
|
|
|
|
I want to reuse some styles, so I created a resources file in the root of my project called AppResources.xaml.
I then copied the styles into it. At the top of my view, I replaced the styles with
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Common;component/AppResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Yet I get a compile error "An error occured while finding the resource dictionary 'pack://application:,,,/Common;component/AppResources.xaml'".
What's the right way to do this?
[UPDATE] Fixed it with <resourcedictionary source="..\Resources.xaml">
If it's not broken, fix it until it is
|
|
|
|
|
If you want to access a resource which is in different assembly, then use the pack URI as follows...
Pack://application:,,,/SampleAssembly;component/SampleFolder1/SampleImage.jpg
If you want to merge two resource dictionaries use the following code
suppose if Dictionary1 and Dictionary2 are your resource xaml files, then to merge these resources
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
<ResourceDictionary Source="Dictionary2.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="BlueBrush" Color="Blue" />
</ResourceDictionary>
</Window.Resources>
|
|
|
|
|
i want to find out row number of a datagrid when i move mouse on it i.e. without clicking any row it must return the row number.
Tilak raheja
|
|
|
|
|
A quick look at the documentation[^] suggests the CellEnter and CellLeave events will give you what you need.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Hi,
I am trying to create stack bart chart in silver light with bars should come in horizental direction by following code
SeriesDefinition tempSeriesForSale1 = new SeriesDefinition();
tempSeriesForSale1.ItemsSource = saleUnits1;
tempSeriesForSale1.IndependentValuePath = "SalesDistrict";
tempSeriesForSale1.DependentValuePath = "saleFromOldCustomer";
//tempSeriesForSale1.Title = "Tik tik";
stackSeriesForSale.SeriesDefinitions.Add(tempSeriesForSale1);
Chart3.Series.Add(stackSeriesForSale);
With this code bars are coming in vertical direction. If I Interchange the Independentvaluepath and dependentvalue path then I gets exception.
Following is the code in .xaml file
<toolkit:Chart Name="Chart3" Title="Repeat Sales" VerticalAlignment="Top" Margin="33,330,176,0"
Height="262">
<toolkit:PieSeries ItemsSource="{Binding}" IndependentValuePath="Name"
DependentValuePath="Types" IsSelectionEnabled="True" >
</toolkit:PieSeries>
</toolkit:Chart>
Can someone please help?
Regards,
Vishal
|
|
|
|
|
[UPDATE] Got it working
I want to style a tooltip so that it looks like a Facebook tooltip[^].
In this design, there can be images, text, links, and buttons, as well as a little triangular pointer. So that leaves a couple of questions...
1) I was thinking that having multiple content presenters would allow me to define the style, and then when it's applied, set the image, text, links, etc. How do you set up multiple content presenters?
2) The triangular pointer... How do you get this to point to the correct spot depending on where the tooltip opens.
Thanks
K
If it's not broken, fix it until it is
|
|
|
|
|
Hi
I am basically trying to create a control that consists of a combobox and some buttons (add, clear etc). I realise I could do it by creating a usercontrol with some codebehind, but I am trying to achieve this by defining a custom control class and a style for the control.
I have done the below based on other custom controls I have done, but the issue I am having is that the ItemsSource is always null and never gets set.
[TemplatePart(Name = ComboBoxControl.INPUTCOMBOBOX_NAME, Type = typeof(ComboBox))]
public class ComboBoxControl : Control
{
#region Constants
const String CATEGORY_NAME = "Custom ComboBox Control";
const String INPUTCOMBOBOX_NAME = "PART_InputComboBox";
#endregion
#region Properties
ComboBox _inputComboBox;
#endregion
#region Dependency Properties
public static readonly DependencyProperty DisplayMemberPathProperty =
DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(ComboBoxControl), new UIPropertyMetadata(String.Empty));
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(ComboBoxControl), new UIPropertyMetadata());
#endregion
#region Dependency Public Properties
public string DisplayMemberPath
{
get { return (string)GetValue(DisplayMemberPathProperty); }
set { SetValue(DisplayMemberPathProperty, value); }
}
public object ItemsSource
{
get { return (System.Collections.IEnumerable)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
#endregion
#region Constructor
public ComboBoxControl() { }
static ComboBoxControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboBoxControl), new FrameworkPropertyMetadata(typeof(ComboBoxControl)));
}
#endregion
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_inputComboBox = (ComboBox)GetTemplateChild(INPUTCOMBOBOX_NAME);
}
}
And the following style:
<Style TargetType="{x:Type local:ComboBoxControl}">
<Setter Property="Label" Value=""/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ComboBoxControl}">
<Border>
<DockPanel>
<ComboBox x:Name="PART_InputComboBox" VerticalAlignment="Stretch" MinHeight="30"
DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
ItemsSource="{Binding Path=ItemsSource, Mode=TwoWay, RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:ComboBoxControl}}, UpdateSourceTrigger=PropertyChanged}"/>
</DockPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
NOTE: I have omitted irrelevant code.
And trying to set it like this:
<ctl:ComboBoxControl ItemsSource="{Binding Path=Users, Mode=TwoWay}"/>
But the value of the combobox itemsource is always null?!
Can anyone help please?
Thanks
|
|
|
|