w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
How to bind MySQL table to datagrid in WPF app
DataTable dt = new DataTable(); using (MySqlConnection conn = new MySqlConnection("Your connection string")) { conn.Open(); string query = "SELECT * FROM table"; using (MySqlDataAdapter da = new MySqlDataAdapter(query, conn)) da.Fill(dt); } yourDataGrid.ItemsSource = dt.DefaultView; This is the code i know to fill a DataGrid with database values. As for printing, it's a bit mor advanced. I think you should consider a google session.

Categories : C#

Bind List to DataGrid in WPF
Change this: public struct SomeInfo { public string Name; public string Description; public string ID; } to this: public class SomeInfo { public string Name {get;set;} public string Description {get;set;} public string ID {get;set;} } WPF does not support binding to fields. Only properties. And a struct is not an appropiate type for the data you're trying to represent.

Categories : Wpf

WPF DataGrid - Bind EditMode
as you said you have your datagrid bind to a collection of objects(class with some properties in it) so just made a property iseditable in your class like this.. private bool _isEdiatble; public bool IsEdiatble { get { return _isEdiatble; } set { _isEdiatble = value; // FirePropertyChanged("Name"); } } and bind it to your each row element like this.. <DataGrid.Columns> <DataGridTemplateColumn > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition />

Categories : Wpf

VB.NET- Is there any way to bind two datatable in a datagrid
a few options: option 1: load the data into one table instead of two option 2: merge the two datatables into one table, if they are all read-only option 3: use unbound columns - bind one table but unbound another table option 4: write a wrapper class to wrap the data and then bind the list (of the wrapper object) to the grid, something like: Public Class MyData Private _rowA As tblARow Private _rowB As tblBrow Sub New(rowFromA As tblARow, rowFromB As tblBRow) _rowA = rowFromA _rowB = rowFromB End Sub Property ColumnA As String Get Return _rowA.ColumnA End Get Set(value As String) _rowA.ColumnA = value End Set End Property ' // Other properties... End Class

Categories : Vb.Net

Bind datagrid with autogeneratecolumn=false
You need to create the column by your self like this : DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.HeaderText = "Lama"; int indexCol = grid.Columns.Add(column);

Categories : C#

Bind List of Employee to DataGrid
Try this: <DataGrid ItemsSource="{Binding Source={StaticResource employeeInfo}, Path=EmployeeList}" AutoGenerateColumns="False" Height="300" Width="300" > <DataGrid.Columns> <DataGridTextColumn Binding="{Binding Path=EmployeeId}" Header="Employee Id" Width="300"/> <DataGridTextColumn Binding="{Binding Path=EmployeeName}" Header="Employee Name" Width="300"/> </DataGrid.Columns> </DataGrid> at the moment you set ItemsSource to whole EmloyeeInfo class and you want to point to your ObservableCollection<Employee>, also you forgot to wrap your column in DataGrid.Columns

Categories : C#

How do I bind a DataGrid Width to a converter?
The comment from sa_ddam213 didn't exactly solve the problem. But it sure did push me into the right direction. To pass the value automatically I had to do the following: I created a property in the window class called TotalColumnWidth. Returning this: myDataGrid.Columns.Sum(c => c.ActualWidth); The xaml is the following: Width="{Binding ElementName=_Root, Path=TotalColumnWidth, Converter={StaticResource ResourceKey=VerticalScrollbarConverter}}" Using the converter mentioned above.

Categories : Wpf

Bind DoubleClick Command from DataGrid Row to VM
You may try this workaround: <DataGrid EnableRowVirtualization="True" ItemsSource="{Binding SearchItems}" SelectedItem="{Binding SelectedItem}" SelectionMode="Single" SelectionUnit="FullRow"> <DataGrid.Columns> <DataGridTemplateColumn Header="....."> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock .....> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseDoubleClick"> <cmd:EventToCommand Command="{Binding MouseDoubleClickCommand}" PassEventArgsToCommand="True" /> </i:EventTrigger>

Categories : Wpf

How to bind list of objects to datagrid?
You need to define public properties in your student class. You cannot bind to fields. WPF supports binding to properties of an object, not fields. See this question for more info: Has it ever been possible to bind to a field in WPF?

Categories : C#

How to bind two dependant ComboBoxes in a DataGrid
here an simple working example how you could use your ViewModel to achieve your needs XAML <DataGrid ItemsSource="{Binding Source}" Width="500"> <DataGrid.Columns> <DataGridTemplateColumn Header="main" Width="100"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding SelectedName}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ComboBox SelectedValuePath="Name" SelectedValue="{Binding SelectedName}"

Categories : C#

Wpf DataGrid bind selection from two Collections of same Count
I Would create a hybrid object: The classes: public class FooBar { public Foo F { get; set; } public Bar B { get; set; } } public class Foo { public int X { get; set; } } public class Bar { public int Y { get; set; } } The view model: public class ViewModel : INotifyPropertyChanged { #region INotifyPropertyChanged Implementation public event PropertyChangedEventHandler PropertyChanged; protected void InvokePropertyChanged(string propertyName) { var e = new PropertyChangedEventArgs(propertyName); if (PropertyChanged != null) PropertyChanged(this, e); } #endregion public ViewModel() { this.FooBars.Add(new Fo

Categories : C#

how to bind multidimensional array of different values to a datagrid
You have error in the linq expression, you should use i variable instead of 0: var datsource = (from i in Enumerable.Range(0, matrix.GetLength(0)) select new clsdatasource(matrix[i, 1], matrix[i, 2], matrix[i, 3])).ToList(); In xaml I have only following code and everything working very well. <DataGrid Name="Matrix_datagrid" /> Example: bool[,] matrix = new bool[5, 5]; matrix[0, 1] = true; matrix[0, 2] = false; matrix[0, 3] = true; matrix[1, 1] = true; matrix[2, 2] = true; Result:

Categories : C#

Bind data from 2 tables to datagrid using mvvm
Just create an additional ViewModel that will serve as Data Item for your rows: public class LocationViewModel: ViewModelBase { public Int32 id {set; get;} public String name {get; set;} public Int32 locationTypeId {set; get;} public Boolean isActive {get; se;} //added property to get the location name public String locationTypeName {set; get;} } Then: public class LocationListViewModel { ObservableCollection<LocationViewModel> dataSource {get;set;} }

Categories : Wpf

Bind DataGrid's PreviewDrop to a command property
EventToCommand Behavior: EventToCommand Place this on your datagrid and bind it to a command property in your viewmodel.

Categories : Wpf

DataGrid bind command to cell click
You can use BeginningEdit event in the DataGrid control to handle this scenario. This event will fires before a row or cell enters edit mode. You can identify the selected column from the EventArgs. Example: private void dgName_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) { if (e.Column.Header.ToString() == "Suggested") { //Do Operation } } If you are using MVVM pattern, there are options to pass EventArgs to VM. If you are uusing MVVMLight Toolkit, there is an option called PassEventArgs and set it to TRUE. In VM, //Relay Command private RelayCommand<DataGridBeginningEditEventArgs> _cellBeginningEditCommand; public RelayCommand<DataGridBeginningEditEventArgs> CellBeginningEditComma

Categories : Wpf

Bind DataGrid to List, but only show selection of T's properties
Your bindings are wrong: you should use Path instead of XPath. The XPath property is only used when binding to an XML data source. <DataGridTextColumn Header="Qty" Binding="{Binding Path=Qty}" /> Note that you can omit the "Path=" part for brevity: <DataGridTextColumn Header="Qty" Binding="{Binding Qty}" />

Categories : C#

trying to bind datagrid item source to a property in another class
Let's say your Dialog control is named DialogControl and has a DependencyProperty named Items defined in its code behind. In the XAML, I would bind this property to the DataGrid like this: <DataGrid ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode= FindAncestor, AncestorType={x:Type DialogControl}}" /> This RelativeSource binding will go off and search through the properties of your DialogControl class and find the Items property. Note: Do NOT set the DataContext of the UserControl to itself. Now in your MainWindow.xaml.cs file where you instantiate your DialogControl, you can set the Items property: DialogControl dialogControl = new DialogControl(); dialogControl.Items = someCollection; dialogControl.Show(); UPDATE >>> Oh I see what you're after now... you wa

Categories : Wpf

How can I bind IsEnabled to whether or not a datagrid has a single item selected?
Define a boolean property and bind it to your TabControl's IsEnabled attribute. Within the SelectedItem property's Setter check if the selected item is null or item count is > 1 based on the condition set true or false to your tab control's IsEnabled binding property Datagrid Binding: <DataGrid ItemsSource="{Binding MySource}" SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> TabControl Binding: <TabControl IsEnabled="{Binding IsTabEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> Datagrid's Selcted Item: Public SelectedItem { get { } set { if(null == SelectedItem || SelectedItem.count > 1) IsTabEnabled = false; } }

Categories : C#

How to Bind checkbox to class object in List of items in datagrid wpf
your Checkbox is binded to Enabled so you should check for m.Enabled instead of m.checkbox List<AwaitingMeds> awaitingMedslistSelected = ( from m in awaitingMedslist where m.**Enabled**.Equals( true ) select m ).ToList<AwaitingMeds>();

Categories : C#

How do I use XAML to bind a DatagridComboBoxColumn to a ViewModel property that isn't in the DataGrid's ItemsSource?
I don't have a compiler in front of me, but I believe the syntax would look something like this: {Binding DataContext.MyProperty, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type MyParentControl}}} EDIT: Actually doing some testing of my own, for some reason the DataGridComboBoxColumn somehow cannot find the item source, but if you template your own combo box column, it works just fine. Not sure why that is, but this may be an acceptable work around. <Window x:Class="WPFTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <DataGrid ItemsSource="{Bin

Categories : C#

how to use complex query to obtain data from sql server and bind to datagrid in c# app
First to improve your query we are going to use inner joins to fetch data SELECT distinct P.f_name, P.l_name, E.grade, M.mentor_name FROM [Person] P INNER JOIN [Exam] E ON P.Person_id = E.Person_id INNER JOIN [Mentor] M ON P.Person_id = M.Person_id Your exceptions points that you are passing your query string to method in a wrong way and compiler is trying to interpret it as code , try this: GetData("SELECT distinct P.f_name, P.l_name, E.grade, M.mentor_name FROM [Person] P INNER JOIN [Exam] E ON P.Person_id = E.Person_id INNER JOIN [Mentor] M ON P.Person_id = M.Person_id");

Categories : C#

Bind dynamic data to wpf datagrid inside rowdetails template
It would be much easier to do it via bindings. You could add a collection of DetailElements to each Element of your dataGrid1's ItemsSource. Now all you have to do is binding this collection to your dataGrid2' ItemsSource and it gets automatically populated with data through the binding. public class DataGrid1SourceItem { public ObservableCollection<DetailItem> DetailItems {get;set;} } The XAML: <Grid> <my:DataGrid Name="dataGrid1" ItemsSource="{Binding}"> <my:DataGrid.RowDetailsTemplate> <DataTemplate> <my:DataGrid Name="dataGrid2" ItemsSource="{Binding Path=DetailItems}"></my:DataGrid> </DataTemplate> </my:DataGrid.RowDetailsTemplate> </my:DataGrid> <

Categories : C#

how to bind one dimensional string array result to datagrid column header
You can not bind gridview header columns. You need to create a loop with string[] header and add columns dynamically. you can go through the below url for how to add columns dynamically in gridview How to add a GridView Column on code-behind? http://www.codeproject.com/Articles/13461/how-to-create-columns-dynamically-in-a-grid-view

Categories : C#

how to bind a datagrid with a class contains object of another class
If I understand question properly, then you should add items of type "generatedMessage" and do binding like: Binding={Binding cycleTime} Binding={Binding cmsg.dlc} ... etc. Generally you shouldn't add items manually to DataGrid. The best way to do it: create ObservableCollection in a ViewModel and set attribute "ItemsSource" in DataGrid: ItemsSource="{Binding Collection}" then add items to this collection, not to DataGrid. To better understood that topic you could read about MVVM pattern ;-).

Categories : C#

Confused on Updating Table using DataGrid
try below, not sure this will solve the issue, but may be you are not dispose/ close the data context correctly with current code. you can use using block like below using (sysSFCDBDataContext SFC = new sysSFCDBDataContext()) { Sales_FGAllocated FGA = SFC.Sales_FGAllocateds.FirstOrDefault(r => r.RowID == Convert.ToInt64(FGAdataGrid.Rows[x].Cells[0].Value)); if (FGAdataGrid.Rows[x].Cells[0].Value != null) { FGA.TotalLoaded = Convert.ToInt64(FGAdataGrid.Rows[x].Cells[6].Value); SFC.SubmitChanges(); } }

Categories : C#

Populating and editing datagrid from a SQL Server table
From: http://social.msdn.microsoft.com/Forums/windows/en-US/e444ca84-3319-4dfa-aa31-46f310dd0c13/datagridview-autosize-rowcolumn 'for the rows DataGridView1.AutoResizeRow(2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader) 'and for columns DataGridView1.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells or you can use for each loop DataGridView1.Columns(i).Width = x

Categories : SQL

DataGrid edition 'EditItem' is not allowed for this view` when bound to a WPF DataGrid
I tried this and the problem is that you have initialized your Level2 collection as Hashset<>. IEditableCollectionView.EditItem() throws this error while trying to update item in Hashset<>. I initialized the collection as List<> and it was working fine. I am not sure why it is not able to update item in hashset, need to look deeper into it. But changing the Hashset<> to List<> will fix this error. Hope it helps Thanks

Categories : C#

Silverlight Datagrid scrolling, DataGrid fires RowLoading event
The RowLoading event is fired because rows are virtualized. With virtualization, rows are created (and loaded) only when they are visible on screen. So every time you scroll down or up a new row is created, loaded and the RowLoading event fired. To disable the virtualization you can try to set this property: VirtualizingStackPanel.VirtualizationMode="Standard" Be aware that this can slow down the performance of your grid if you have a lot of rows.

Categories : Database

how to bind a wpf table to an observablecollection?
The FlowDocument control does not support DataBinding as explained here While there are many great features in flow documents, if your documents are generated from dynamic data, you have a bit of a problem: there is no support for data binding in flow documents. The flow document elements (Section, Table, Run, Paragraph and the like) are dependency objects, but don't define any dependency properties that would allow you to dynamically change or generate content. There is a work around given at the above link, which might be helpful for you.

Categories : C#

Binding ComboBoxColumn to collection from DataGrid's ItemsSource in WPF DataGrid
MSDN: DataGridComboboxColumns says: To populate the drop-down list, first set the ItemsSource property for the ComboBox by using one of the following options: A static resource. For more information, see StaticResource Markup Extension. An x:Static code entity. For more information, see x:Static Markup Extension. An inline collection of ComboBoxItem types. So basically to just bind to data object`s collection property it`s better to use DataGridTemplateColumn: <DataGridTemplateColumn Header="Log"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource="{Binding log}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> This type of c

Categories : Wpf

Bind collection of models to a table
For list view rendering I would recommend taking a look at how Backbone Marionette solved these problems, eliminating list generation boilerplate in your code.

Categories : Backbone Js

How to bind inner array in a table with knockout
Please could you take a look at this fiddle and tell me what is not working. Because for me it works well. View : <table> <tbody data-bind="foreach: reportData"> <tr> <td data-bind="text: Category"></td> </tr> <!-- ko foreach: Items --> <tr> <td data-bind="text: Name"></td> </tr> <!-- /ko --> </tbody> </table> JS: data = [{ "Category": "First Category", "Id": 1, "Items": [{ "Name": "First Name" }, { "Name": "Second Name" }] }, { "Category": "Second Category", "Id": 2, "Items": [{ "Name": "First Name"

Categories : Xml

How to bind Knockout.js to existing table grid?
One way would be to pass your initial data into your view model. Since you are using asp.net it would look something like this: //Dump raw data into javascript variable var data = @Html.Raw(ViewBag.Data); function ViewModel(data) { var self = this; //Unpack raw data self.lookupCollection = ko.observableArray(data.lookupCollection); } //initialize view model var viewModel = new ViewModel(data); ko.applyBindings(viewModel);

Categories : Javascript

How to bind data in html table in asp.net web form
Aslam, Yes you can declare a public variable/property in your aspx.cs class. You can assign that variable/property in Page_Load or any other appropriate event and then you can directly access it in your aspx. following is the example: public DataSet ds; protected void Page_Load(object sender, EventArgs e) { ds = new DataSet(); //load your ds from database } Following is the code to use table 0 from database to create table in aspx <table> <% foreach(DataRow row in ds.Tables[0].Rows) { %> <tr> <td><%= row["columnName"] %></td> </tr> <% } %> </table> Hope this helps

Categories : Asp Net

bind a table on click event of button
I'm not exactly sure what you are asking. But if you want to get the list on the click of a button you can use jQuery .getJSON (http://api.jquery.com/jQuery.getJSON/) to retrieve the list data and then insert it with javascript. Or you could render the list in the action and simply use json .get and insert the result.

Categories : Asp Net Mvc

KnockoutJS - Bind an object to a table depending on a variable
Ok, you can put the table into a template, if you only want to have it in your page once, but this works: <tbody data-bind="visible: $root.dataTitle() === 'Warnings', foreach: $data.Warnings.content"> <tr> <td data-bind="text: number"></td> <td data-bind="text: description"></td> </tr> </tbody> <tbody data-bind="visible: $root.dataTitle() === 'Errors', foreach: $data.Errors.content"> <tr> <td data-bind="text: number"></td> <td data-bind="text: description"></td> </tr> </tbody> You've basically got one table for each section, and only show the one that you want. I made some other changes to the view model whilst trying to get this to work, I'm n

Categories : Javascript

Bind gridview using jquery : Have table data clickable
You are closing the anchor element in your code twice... <a href="#" onclick="getStock()" value=' + codes + ' />' + codes + '</a> Should be: <a href="#" onclick="getStock()" value=' + codes + '>' + codes + '</a> (note the removed "/" right before the anchor's greater-than character)

Categories : Javascript

Bind table with dynamic rows and columns from two lists
This answer no longer applies after the question was updated. I am not sure how your table cells are laid out. In your implementation, for example, there is no place to output the date value. Assuming I haven't completely misunderstood the layout you want, you could rewrite your element <template> content as follows: <polymer-element name="calendar-table"> <template> <table> <tr> <td template repeat="{{people}}">{{name}}</td> </tr> <tr> <td template repeat="{{dates}}">{{}}</td> </tr> </table> </template> <script type="application/dart" src="calendartable.dart"></script> </polymer-element> That would put the 2 names in the first

Categories : Dart

How to bind Command to ios table section header click?
There are a few ways you could achieve this effect. For just your current requirements, the easiest way to achieve it would be to add just a single command to the TestTableSource and to have that command passed on to your section header inside the Action handler. public class TestTableSource : MvxBaseTableViewSource { public ICommand FooCommand { get; set; } // existing code public override UIView GetViewForHeader(UITableView tableView, int section) { var view = new OrderGuestSectionHeader(OrderGuestSectionHeader(tableView, section), () => { Debug.WriteLine("selected " + section.ToString()); if (FooCommand != null) FooCommand.Execute(null); }); return view; } } This Command can then be bound to the ViewModel by ad

Categories : IOS

How to bind up and down arrow key to enable navigating through table rows?
It's actually not that hard to find next and prev For example $(window).keyup(function (evt) { if (evt.keyCode == 38) { // up $('tbody tr:not(:first).selected').removeClass('selected').prev().addClass('selected') } if (evt.keyCode == 40) { // down $('tbody tr:not(:last).selected').removeClass('selected').next().addClass('selected') } }); FIDDLE

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.