|
hi guy's
i have code in c# windows form i want to view it form in emulator in WP7 when run this program .... i ask it allow and how to view form in c# view it in another program (emulator wp7 ) plz?
|
|
|
|
|
You can't view a Windows Form in the WP7 emulator. The emulator is targetted specifically at the Silverlight runtime that Windows Phone uses, which uses a very specialist version of the .NET runtime.
|
|
|
|
|
okey thnx
|
|
|
|
|
Hi,
i have 2 tabitem, each one cotain a wpf gdatagrid
i want to pass data from grid1 in tabitem1 to grid2 in tabintem2
when i click on tab item2 or on boutton.
i tried this code but i get exception:
L'élément possède déjà un parent logique. Il doit être détaché de l'ancien parent avant d'être attaché au nouveau.
private void btnValidate_Click(object sender, RoutedEventArgs e)
{
for (int j = 0; j < i - 1; j++)
{
TextBlock x = dgrecep.Columns[0].GetCellContent(dgrecep.Items[j]) as TextBlock;
if (x != null)
{
if (v.validate(x.Text))
{
dgrecep2.Items.Add(dgrecep.Columns[0].GetCellContent(dgrecep.Items[j]));
}
else
{
MessageBox.Show("non valide");
}
|
|
|
|
|
Why on earth are you doing this via code behind? You really need to read up on MVVM, and judging by the number of questions you have posted in this forum, I would suggest that you need to read a basic book on WPF, such as Adam Nathan's excellent WPF Unleashed.
|
|
|
|
|
I am a student and I'm doing my final year project and this project is the first work with WPF, I downloaded a book and I make every effort to learn because I believe in that "le difficile c'est le chemin" and I asked a lot of questions because I have a month to develop my application also it is not MVVM because company demanded another architecture...thank you
|
|
|
|
|
I find it hard to believe that a company would demand no architecture whatsoever. What you are doing is code behind and is not suited to solving the problem you are trying to solve. Now is the time for you to embrace the right way to do it.
|
|
|
|
|
hello Everyone
Can someone please tell me, what is the database SQL query to display the name of the table only in to datagrid...
kind regards
roni
|
|
|
|
|
Presumably you are using sql server - look into the sys.sysobject and the system views, all the information is in there. The system views were set up in 2005 (I think) specifically for this.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft Holmes
Actually I'm using Microsoft access 2007 database, I'm not using the SQL Server, maybe you can have a look at the code below and tell me what am I doing wrong...
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
string CmdString = string.Empty;
using (OleDbConnection myConnection = new OleDbConnection(ConString))
{
CmdString = "SELECT FoodMenu FROM MSysObjects WHERE (FoodMenu Not Like 'MSys*') AND (Type In (1,4,6)) ORDER BY FoodMenu";
OleDbCommand comm = new OleDbCommand(CmdString, myConnection);
OleDbDataAdapter sda = new OleDbDataAdapter(comm);
myConnection.Open();
DataTable dt = myConnection.GetSchema("Tables");
foreach (DataRow dataRow in dt.Rows)
{
DataGridMenuTables.Items.Add(dataRow["FoodMenu"].ToString().Trim());
}
}
}
Basically what I'm trying to do is to display the database table name in to datagrid, but i can't figur out the SQL query how to do it, maybe you can help me and solve it...
kind regards
Roni
|
|
|
|
|
What on earth does this have to do with WPF or Silverlight? You are aware that we have a database forum where you could ask this question aren't you?
|
|
|
|
|
You'll be able to see the event if you hook the preview keydown event. However, this will occur BEFORE the undo is done, so you'll have to consider that.
|
|
|
|
|
Wow... how lame... can you "fake it" by deriving a class from TextBox and overriding the OnKeyDown method?
If the above suggestion doesn't work, my only other suggestion to hook the event would be to use interop and use native keyboard hooks. Dunno if that's allowed in SL though.
|
|
|
|
|
Just spitballing here, but you could always create an Attached Behavior that hooks into the TextBox elements inside your DataGrid and add the behaviour you want in. I would look to implement this by having a global undo manager service which I would use to hold the undo/redo state in.
|
|
|
|
|
i tried to bind data from datatable to wpf datagrid with code behind
<pre lang="c#">
Binding b = new Binding();
ExcelParser exc = new ExcelParser();
DataTable dt = exc.GetDataTableExcel(datasource);
b.Source = dt.DefaultView;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
b.Path = new PropertyPath("F1");
this.dgvreceipient.SetBinding(TextBlock.TextProperty, b);
when i use xamlcode it work:
<DataGrid.Columns>
<DataGridTemplateColumn Header="Adress" Width="500" IsReadOnly="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
but i need to have this on code behind.
|
|
|
|
|
Hi Friends,
I have developed a WPF application. This tool will display the report in DocumentViewer.
Background: I am converting a UserControl content in to a FixedDocument and then displays it in the DocumentViewer.
Problem: The DocumentViewer has the default option to print the content. But we cannot save it as a MS Document or PDF file.
My findings so far: I can export the FixedDocument to a XPS file using XpsDocument.
Is there any way to export/save the FixedDocument or DocumentViewer content to a MS Word document?
Please give your openion/suggestions.
Thanks in advance,
Regards,
Suresh Kumar.B
Suresh Kumar
modified 9-May-12 8:13am.
|
|
|
|
|
Hi,
I am using wpf C# to develop a project , in this i need following..
1) add formatted text on canvas
2) resize text portion between thumbs (no need to resize whole text)
3) edit text by mouse double clicking (Show cursor to enter text.)
any control support the above three options in wpf? How can i do this ?please help me soon with a solution..
modified 9-May-12 0:03am.
|
|
|
|
|
Take a look at the richtextbox.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi, I try to import data from an Excel file and display it in a datagrid, the data are email addresses. i want that data will be shown on
<DataGridTemplateColumn Header="Adress" Width="500" IsReadOnly="True">
but when i click on boutton, another DataGridColumn appears with data, but i want that data shown on DataGridColumn="Adress"
code of parse:
public class ExcelParser
{
public DataTable GetDataTableExcel(string datasource)
{
OleDbConnection theConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + datasource + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");
theConnection.Open();
OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Feuil1$]", theConnection);
DataTable dt = new DataTable();
theDataAdapter.Fill(dt);
return dt;
}
xaml:
<DataGrid HeadersVisibility="Column" AutoGenerateColumns="True" Height="296" HorizontalAlignment="Left" Margin="23,8,0,0" Name="dgvreceipient" VerticalAlignment="Top" Width="582" MinRowHeight="30" MinWidth="0" DataContext="{StaticResource {x:Static SystemColors.ActiveCaptionBrushKey}}" MinColumnWidth="100" SelectedValuePath="id" ItemsSource="{Binding Customers}" AlternatingRowBackground="Gainsboro" AlternationCount="2">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Adress" Width="500" IsReadOnly="True">
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Validate" Width="200" IsReadOnly="True">
</DataGridTemplateColumn>
</DataGrid.Columns>
boutton click excel
code behined:
private void btnExcel_Click(object sender, RoutedEventArgs e)
{
wpfOpenfiledialog o = new wpfOpenfiledialog();
o.openfich(1);
datasource = o.filename;
ExcelParser exc = new ExcelParser();
DataTable dt = exc.GetDataTableExcel(datasource);
}
|
|
|
|
|
Your view binding is to Customers
Then you assign the resulting dataset! to the datagrid directly - the data should be put into Customers not the control
Check the content of the datatable after it has loaded and make sure the columns are all what you expected. Then put the rows into the customer container, presuming it is an observablecollection
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The issue is that you are setting the AutoGenerateColumns property of the DataGrid to true, which will generate it's own columns (one for each field in the datatable) as well as show your template columns (which are not bound to anything by the way, so will not display any results). You have 2 options here:-
1. Forget about your template columns, and leave AutoGenerateColumns on. Then in your SQL query you should only select the columns you want displayed, and use aliases to get the correct headers for your columns i.e.
SELECT name AS Name, emailaddress AS Address FROM youtable . This will give you the results you want except for column width.
2. Turn AutoGenerateColumns off in your DataGrid, and the use the DisplayMemberBinding property of your template columns to bind the column to the datatable field i.e
<DataGridTemplateColumn Header="Adress" DisplayMemnerBinding={Binding Path=emailaddress} Width="500" IsReadOnly="True"> . This will also get you your desired result with column widths.
Personally I never use DataTables to bind to WPF controls, preferring to have a class that holds my object properties, and then having an ObservableCollection of that class that holds all instances of that class to bind to the DataGrid.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
thnk you, please I tried to use interface: this is the code but it doesn't work
public interface Iimportdata
{
DataView GridData { get; set; }
}
private DataView Data = null;
public DataView GridData
{
get
{ return Data;
}
set
{
Data = value;
NotifyPropertyChanged("GridData");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private void btnExcel_Click(object sender, RoutedEventArgs e)
{
ExcelParser exc = new ExcelParser();
DataTable dt = exc.GetDataTableExcel(datasource);
Iimportdata imp = Window.GetWindow(this) as Iimportdata;
imp.GridData = dt.DefaultView;
gbReceipient.Visibility = Visibility.Visible;
btnValidate.Visibility = Visibility.Visible;
}
XAML:
<DataGridTemplateColumn Header="Adress" Width="100" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=GridData}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
|
|
|
|
|
Hello Everyone
I did asked a question to my problem couple of days ago on: How can I display all the details of the employee in the textboxes, comboboxes, and checkbox when I click on the cell of the DataGrid?
Well somehow I managed to solve my problem with the help on searching on the internet, but I'm facing another problem.
When I run my application I'm displaying only the names of the employee from the database on the DataGrid, then when I click on DataGrid cell (of the employee name, to display all the details of that employee into textboxes, comboboxes, and checkbox) some-how it repeats the details of the employee into textboxes.
To be more clear to my problem:
In my database table (EmployeeDetails table) I have 2 employee record details,
These 2 employees (their names will be displayed on the DataGrid)
When I click on the first employee name on the DataGrid cell to display his/her details
When I click on the second employee name on the DataGrid cell to display his/her details etc. etc...
Could someone please view the code I provided below and tell me what am I doing wrong...
DataGrid xaml code:
<DataGrid Height="490" HorizontalAlignment="Left" Margin="6,8,0,0" Name="GridViewEmployeeName" VerticalAlignment="Top" Width="200" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Background="{x:Null}" FontFamily="Verdana" FontWeight="Bold" FontSize="16" GridLinesVisibility="None" BorderBrush="Silver" RowDetailsVisibilityMode="Visible" CanUserResizeRows="False" ItemsSource="{Binding}" SelectionChanged="GridViewEmployeeName_SelectionChanged" SelectionMode="Single" IsSynchronizedWithCurrentItem="{x:Null}" CanUserResizeColumns="False" AutoGenerateColumns="False" HeadersVisibility="Column" EnableRowVirtualization="False" CanUserAddRows="False" RowHeight="22">
<DataGrid.Columns>
<DataGridTextColumn FontSize="12" FontWeight="Bold" Header="Employee Name" IsReadOnly="True" Width="200" Binding="{Binding Name}" CanUserResize="False" FontFamily="Verdana" />
</DataGrid.Columns>
</DataGrid>
C# code Window Load displaying only names of the employee in DataGrid
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
string CmdString = string.Empty;
using (OleDbConnection conn = new OleDbConnection(ConString))
{
CmdString = "SELECT Name FROM EmployeeDetails";
OleDbCommand comm = new OleDbCommand(CmdString, conn);
OleDbDataAdapter sda = new OleDbDataAdapter(comm);
DataTable dt = new DataTable("EmployeeDetails");
sda.Fill(dt);
GridViewEmployeeName.ItemsSource = dt.DefaultView;
}
}
C# code
private void GridViewEmployeeName_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Desktop\iPosSystem\iPosSystemMenu\iPosSystemMenu\DataBase\RestaurantMenu.accdb;Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(ConnStr);
string sql = "SELECT Name, NIN, Phone, Address, PostCode, City, JobTitle, AccessCode, AccessLevel, AssignTableAccess FROM EmployeeDetails";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
txtFullName.Text += dr["Name"].ToString();
txtNIN.Text += dr["NIN"].ToString();
txtPhoneNumber.Text += dr["Phone"].ToString();
txtAddress.Text += dr["Address"].ToString();
txtPostCode.Text += dr["PostCode"].ToString();
txtCity.Text += dr["City"].ToString();
JobTitleComboBox.Text += dr["JobTitle"].ToString();
txtAccessCode.Text += dr["AccessCode"].ToString();
AccessLevelComboBox.Text += dr["AccessLevel"].ToString();
AssignTableAccessCheckBox.IsChecked = dr["AssignTableAccess"].Equals(true);
}
dr.Close();
conn.Close();
}
}
Could someone help me on this please I'm new to WPF...
Kind Regards to everyone
Lapeci
|
|
|
|
|
i try to change the size of text in ritchbox with code behind
TextRange tr = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
tr.ApplyPropertyValue(FontSizeProperty, (double)9);
but i want to change
tr.ApplyPropertyValue(FontSizeProperty, (double)9) by
double size=Convert.ToDouble(comboboxfontsize.selectedItem)
tr.ApplyPropertyValue(FontSizeProperty, size)
i get an exception
Impossible d'effectuer un cast d'un objet de type 'System.Windows.Controls.ComboBoxItem' en type 'System.IConvertible'.
so how can i get the value selected item?
|
|
|
|
|
I don't know how you are populating the ComboBox, but I assume it is in the XAML. In this case the SelectedItem would be a ComboBoxItem which does not implement the IConvertible interface and so cannot be converted to a double. Personally, I would use WPF's binding mechanism to implement this using 2 properties, and ObservableCollection<int> to hold the allowed font sizes, and an int property to hold the selected font size, something like this:-
public ObservableCollection<int> Fonts
{
get
{
return new ObservableCollection<int>() { 8, 9, 10, 12, 14 };
}
}
int selectedFontSize;
public int SelectedFontSize
{
get
{
return selectedFontSize;
}
set
{
if (selectedFontSize != value)
{
selectedFontSize = value;
OnPropertyChanged("SelectedFontSize");
}
}
}
(this assumes you user control / window implements INotifyPropertyChanged ). Then you can just create the bindings in your XAML like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding Fonts}" SelectedItem="{Binding SelectedFontSize}" Width="200" HorizontalAlignment="Left"/>
<RichTextBox Grid.Row="1">
<FlowDocument FontSize="{Binding SelectedFontSize}">
<Paragraph >
Hello World!
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
and that is all there is to it, not forgetting to set the DataContext of your user control / window to itself like this in the constructor:
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|