C# :: WPF Cascading DataContext Like With DataGrid?
Dec 15, 2014
I'm trying to create custom WPF control, similar to DataGrid. DataGrid was great as a base class for a different custom control I needed, because I could do something like this:
<shared:MyDataGrid ItemsSource="{Binding Persons}" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Width="4*" />
<DataGridTextColumn Binding="{Binding Phone}" Width="3*" />
<DataGridTextColumn Binding="{Binding Email}" Width="3*" />
</DataGrid.Columns>
</shared:MyDataGrid>
where Person class would be like this:
public class Person
{
public string Name {get; set;}
public string Phone {get; set;}
public string Email {get; set;}
}
... and I can reuse it elsewhere with collections of different type, binding its properties to columns of different width and style.
What I need now is something similar, but differs in a way, that DataGrid is no longer good fit for the base class.
What I'm interested in is: how does DataGrid "tell" the columns in Columns collection, to have the type of ItemsSource bound collection as a DataContext? How does the Name property of Person class become available to the column in DataGrid.Columns?
View 3 Replies
ADVERTISEMENT
Apr 15, 2015
I'm a bit unsure on where to put cascading deletes in my models and how far they extend.
I've got four tables
TrafficLog
has a One to One with
TransactionHistory
Has a zero to Many with
OutgoingService
and
Exceptions
Now i'd like to put cascading deletes on, so that if i delete a record from TrafficLog it deletes from the other three.
So do i set up my model with cascade delete just on the primary like this
modelBuilder.Entity<TCC_ArchivedApplicationTrafficLog>()
.HasRequired(TCC_ArchivedTransactionHistory)
.WithRequiredDependent()
.WillCascadeOnDelete(true);
or do i need to enable it on the other three tables too?
View 3 Replies
View Related
Apr 3, 2015
I am trying to get a datagrid working in my program with populating a simple set of data. Which i can then expand on and bring in data from a database.
But even this little simple test datagrid does not seems to be working.
XAML Code
<DataGrid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" Name="DataGrid_1" ItemsSource="{Binding DataGridData}"></DataGrid>
<Button Grid.Row="6" Grid.Column="2" Margin="10" FontSize="12" Command="{Binding Path=GetDataGridData_Command}">Get Data</Button>
[Code].....
View 3 Replies
View Related
Nov 20, 2014
I want to print the current grid values while clicking the print option ..
View 7 Replies
View Related
Feb 9, 2014
I have been struggling to implement a method for reading data from SQL server to my C# program. In the C# program I prepared a DataGrid (not a DataGridView) for the data to be shown in it using a button "Load Table". Now I just want to read a table which has 4 different columns which I also added to the DataGrid.
I have a DataAccessDB class and this is the code for establishing a connection:
const string DB_CONNECTION = @"It is known to me";
SqlConnection con;
SqlCommand cmd;
Controller myController;
Then, there is a code to reference controller:
public DataAccessDB(Controller refController) {
con = new SqlConnection(DB_CONNECTION);
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
myController = refController;
}
And this is the code for a List which I am going to use for filling the data to a DataGrid:
public List<ProductionStock> GetProductionStockFromDB() {
int productionStockId, amount;
decimal price;
string name, descript;
[code]....
And now the main part - how to read the data when I press a LoadTable button. The point here is that I already defined connection strings here as you can see, and in the method itself I guess I should not repeat it. The tutorials I have seen they do it everything in that one button.
View 10 Replies
View Related
Mar 30, 2014
i have the following code
protected void Page_Load(object sender, EventArgs e)
{
List<Product> Products = DbConnectivity.LoadProduct();
updateTable(Products);
[Code].....
the code works and produce a table and fills the grid, what im trying to do is get this information into a DataGrid, so i can get rows selected by user. ive tried many ways ie convert the list into a datatable and display but produces errors, ive done the following,
pageLoad....{
FillDataGrid();
DataGridProduct1.DataBind();
}
[Code].....
this populates, but couldnt seperate the SQL connection apart, and it makes no use of the class product
View 6 Replies
View Related
Mar 29, 2014
im trying to populate a datagrid, i have a datbase class
public static List<Product> LoadProduct()
{
....................
}
i have a product class
gettor & settors
public Product(int id, string Name, double Price, int Quantity)
{
productId = id;
productName = Name;
productUnitPrice = Price;
productQuantity = Quantity;
}
ive added the HTML code to set up the datagrid, which i can see via design tab, but filling it up is harder.
i uderstand it needs a
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
sqlDataAdapter1.Fill();// where it require a dataset or datatable
DataGridProduct.DataBind();
as it requires a datatable i converted the list to a datatable when i run it it says null, im not sure where im going wrong, i noe the list works as i tried populating on a table.
public static DataTable ToDataTable<T>(List<T> items)
{
}
View 1 Replies
View Related
May 21, 2014
I have a datagrid, which has a column called Status. In the database, the field is a text field that can have the values up, down, or danger.
I needed to display the status as a "light" as per client request, so I have a StatusToImageConverter class that receives the status, and returns the proper image to display in the datagrid column. Works fine.
Now the issue I am having... I have a combo box above the datagrid for the user to filter the results if desired. The filtering works fine, but the newly displayed devices do not have their status light. In the Status column, nothing appears after the user filters. I think it may have to do with the fact that I am not re-initializing the datagrid, but just refreshing it? That's just my educated guess.
XAML:
In the UserControl Resources:
<local:StatusToImageConverter x:Key="ImageConverter" />
In the DataGrid Control:
<DataGridTemplateColumn Header="Status" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
[Code].....
View 5 Replies
View Related
Oct 8, 2012
how to create e button in Datagrid for each row with the function to Expand/Collapse when it is clicked.
I want to show some data for the row where the button is clicked.
View 5 Replies
View Related
Jul 6, 2014
I want to be able to keep on adding a row to my datagrid every time i click a button, the row will hold the text of the text box and the combobox in its individual cells, is there a way to do this without inserting a ridiculous amount of code?
Attached image(s)
View 1 Replies
View Related
Jul 19, 2014
I have made a datagrid in a WPF and added a button to add rows, here is the code for that:
this.itemListDataGrid.Items.Add(new TextBox());
Also, I have already got 3 colums in the datagrid pre-added by me, so when the rows are added I click on one to edit it and it comes up with error edit item not allowed.
View 7 Replies
View Related
Jun 5, 2012
I have the following code in the cellmouse event to get information from a selected row.
private void dt_Grid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
datagrid.Rows[0][0] = dt_Grid.Rows[e.RowIndex].Cells[0].Value.ToString();
datagrid.Rows[0][1] = dt_Grid.Rows[e.RowIndex].Cells[1].Value.ToString();
datagrid.Rows[0][2] = dt_Grid.Rows[e.RowIndex].Cells[2].Value.ToString();
[Code]...
but when i select a collumn, i recive an error because i'm selecting a cell with the mouse and i dont have code for that selection. My question is how can i put an "if" on the beguining of the event so that he can determine if it's a header or not.
View 1 Replies
View Related
Apr 17, 2012
How do I order the value of the selected cell in a datagrid to textbox in another form
View 1 Replies
View Related
May 7, 2014
How can I update my dataGrid when a user makes a selection in the combobox?
Here's my ComboBox:
<ComboBox HorizontalAlignment="Left"
Margin="125,110,0,0"
VerticalAlignment="Top"
[Code]....
View 5 Replies
View Related
May 7, 2012
In my WPF application I created a LINQ to SQL entities class. Then I created a partial class and there add code to my entity class. Below is the code of it:
namespace Mynamespace {
partial class rts_index {
#region Fields
/// <summary>
/// Status:
/// "Selected" - true, "Unselected" - false.
/// </summary>
private bool _is_selected;
[code]....
Then I executed LINQ to SQL. Works perfectly well. Then I bound WPF Datagrid radiobutton column to is_selected property of the partial class. Below is XAML code:
.
.
.
<Window.Resources>
<CollectionViewSource x:Key="rts_indexViewSource" d:DesignSource="{d:DesignInstance my:rts_index, CreateList=True}" />
</Window.Resources>
[code]....
And here I have the problem. When I'm changing the radiobutton status from Unchecked to Checked it doesn't change the value of is_selected property from false to true in the partial class. I don't know why.
View 1 Replies
View Related
Apr 25, 2014
How do I bind a DATE column in a DataGridView Control to a DatePicker control (using C#)? I already have the DataGridView control bound to a database stored procedure which takes a DATE value as a parameter and selects joining table based on the results.
View 7 Replies
View Related