select command |
How to use a select command |
Wie rufe ich mit einem Select-Befehl Daten aus der Datenbank? |
public DataTable selectDBS(string sSQL) { try { FbDataAdapter da = new FbDataAdapter(sSQL, _cnn); DataTable dt = new DataTable("RELATIONS"); da.Fill(dt); return dt; } catch (Exception e) { MessageBox.Show("Fehlerhafte SQL-Anweisung\r\n" + e.Message + "\r\n" + sSQL, "SQL-Fehler", MessageBoxButton.OK, MessageBoxImage.Error); return null; } }
dbs.txt |
wrapper class |
how can I create a wrapper class ? |
wie kann ich die DataTable in eine Klasse umwandeln? |
1) You need a class "Department" with an interface "INotifyPropertyChanged" 2) each attrib must send an Change-Event 3) you need an array to save the objects (ObservableCollection<Department>) 4) Now, you only need to set the ItemsSource from a datagrid 5) datagrid.ItemsSource = dept_observerlist |
navigator in WPF? |
how can I use a navigatorbar? |
wie kann ich einen Navigator-Leiste einfügen? |
First Solution: a navigatorbar in each form 1) create a grid 2) insert the buttons with images 3) create the click-events
Second Solution: a navigatorbar as Usercontrols 1) you create an usercontrol 2) insert the buttons with images 3) create the click-events in the usercontrols 4) create an interface "INavigatorbar" 5) the constructor get the parent "INavigatorbar" 6) in the click-events call the methods from "INavigatorbar"
navigatorbar_xml.txt
navigatorbar_cs.txt
navigatorbar_interface.txt |
problems with the navigatorbar event |
how can I scoll the datagrid rows? |
wie kann ich eine Zeile in einem Datagrid ansteuern? |
1) Change the selectedIndex 2) scroll to View 3) Focus setzen
Prev-Event:
datagrid.SelectedIndex = datagrid.SelectedIndex - 1; datagrid.ScrollIntoView(datagrid.SelectedItem); datagrid.Focus();
navigatorbar_datagrid.txt |
ObservableCollection with delete items, datagrid |
how can I "save" the delete-Object and recognize the new and modify Objects to modify the database? |
wie kann ich die gelöschten Objekte mit merken und die neuen und geänderten Objekte erkennen? Dann kann ich damit die Datenbank ändern. |
1) ModelObject has two new attribs 1a) bool newAttrib=true 1b) bool modifyAttrib=false
2) in the wrapper-Class (dataTable -> ObservableCollection ) change all attribt to false 2a) newAttrib=false 2b) modifyAttrib=false
3) in each setter-method set the modify-attrib
4) Now each new object has set the newAttrib
5) save the delete-object in a separate ObservableCollection
6) ask the user to save the changes (perhaps ;-)
7) save methods 7a) delete the items in the delete-list 7b) insert the new items 7c) update the modify items, that are not new
datagrid_new_delete_modify.txt |
datagrid create manuel columns |
how can I create manuel the columns from an class? |
wie kann ich manuell die Spalten in einem Datagrid erzeugen |
Type myType = typeof(ModelEmployee); PropertyInfo[] propertyInfos = myType.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { System.Diagnostics.Debug.WriteLine(propertyInfo.Name); DataGridTextColumn dataColumn = new DataGridTextColumn(); dataColumn.Header = propertyInfo.Name; Binding binding= new Binding(propertyInfo.Name); binding.Mode = BindingMode.TwoWay; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; dataColumn.Binding = binding; datagrid.Columns.Add(dataColumn); }
datagrid_manual_column.txt |
sort in a datagrid |
How can I sort two columns in a datagrid? |
Wie kann ich zwei Spalten automatisch sortieren? |
ICollectionView collView = null; datagrid.ItemsSource = observerItems; collView = CollectionViewSource.GetDefaultView(datagrid.ItemsSource); collView.SortDescriptions.Add(new SortDescription("Lastname", ListSortDirection.Ascending)); collView.SortDescriptions.Add(new SortDescription("Firstname", ListSortDirection.Ascending));
datagrid_sort_column.txt |
datagrid computes by column |
I have a table with a "computes by" column.
Samples:
length=to-from yearsalary=monthsalary*12 name=Lastname+', '+firstname
How can I updated the "computes by column"? |
Ich habe eine Entity-tabelle mit einer Spalte, die automatisch berechnet wird. In Firebird nennt man das "computes by"
Beispiele:
length=to-from yearsalary=monthsalary*12 name=Lastname+', '+firstname
Wie kann man diese Spalte automatisch updated? nach dem Speichern und neuladen ist der Wert ja da, doch während des Editierens? |
The problem ist, that the Change-Event is fired with the previous-Value, so without any code, you see the last change.
Solution:
You must implemented a separate method to fire an update-Event
datagrid_computed_by.txt
// After the cell lost the focus, the yearsalary ist set to the new value private void datagrid_CellEditEnding(...) { if (col.Header.Equals("Monthsalary")) { DataGridRow row = e.Row; ModelEmployee empl = (ModelEmployee)row.Item; empl.updateYearsalary(); // important }
In the class ModelEmployee:
public void updateYearsalary() { NotifyPropertyChanged("Yearsalary"); System.Diagnostics.Debug.WriteLine("updateYearsalary: " + yearsalary); } |
datagrid with separate textbox |
I want a datagrid with an additional textbox. How ? |
Wie kann ich neben den Datagrid ein und mehrere Textbox anzeigen lassen? |
The textbox need two values:
1) the instance from the array 2) the name of the attrib
Solution:
you create a grid or any other layout with a textbox. the layoutcontainer get the instance with the datacontext. the textbox get the value swith the binding-option.
XAML:
<grid Name="gridDetails"> <TextBox Name="tFirstname" Text="{Binding Path=Firstname, UpdateSourceTrigger=PropertyChanged }" /> </grid>
CS:
gridDetails.DataContext = empl_items[0];
datagrid_additional_textbox.txt |
datagrid with separate checkbox |
I want a column checkbox in a datagrid. |
Wie kann ich ein bool'sches Attribut als Checkbox in einem Datagrid darstellen? |
<DataGridCheckBoxColumn Header="IsGoodWorker" Binding="{Binding Path=IsGoodWorker, UpdateSourceTrigger=PropertyChanged}" /> |
datagrid database "AllInOne" samples |
Can I get an "AllInOne"-Sample"? |
Gibt es ein "AllInOne"-Beispiel? |
SURE
Only program: Database_AllInOne.zip Picture: Database_AllInOne1.png
Projekt: Project_Database_AllInOne.zip
main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with master/detail |
Can I get an "AllInOne"-Sample" with two master/details-datagrids? |
Gibt es ein "AllInOne"-Beispiel mit zwei Master/Detail-Datagrids? |
SURE
Only program: Database_AllInOne2.zip Picture: Database_AllInOne2.png
Projekt: Project_Database_AllInOne2.zip
main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with DataGridComboBoxColumn and DataGridCheckBoxColumn |
Can I get an "AllInOne"-Sample" with a DataGridComboBoxColumn and a DataGridCheckBoxColumn? |
Gibt es ein "AllInOne"-Beispiel mit einer DataGridComboBoxColumn und einer DataGridCheckBoxColumn? |
SURE Solution with a column-Definition in XAML
Only program: Database_AllInOne3.zip Picture: Database_AllInOne3.png
Projekt: Project_Database_AllInOne3.zip
main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |
datagrid database "AllInOne" samples with DataGridComboBoxColumn and a DataGridCheckBoxColumn Code behind |
Can I get an "AllInOne"-Sample" with a DataGridComboBoxColumn and a DataGridCheckBoxColumn ? |
Gibt es ein "AllInOne"-Beispiel mit einer DataGridComboBoxColumn und einer DataGridCheckBoxColumn ? |
SURE Solution with a column-Definition in CS !!!
Only program: Database_AllInOne4.zip Picture: Database_AllInOne4.png
Projekt: Project_Database_AllInOne4.zip
main.xaml: MainWindow.xaml main.cs: MainWindow.xaml.cs |