Translate

Samstag, 27. Februar 2016

C#-Komplette Klasse in XMl-Datei speichern

private void WriteItemsToXMLFile<T>(T item, string fileName)
        {
            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                XmlTextWriter textWriter = new XmlTextWriter(fileName, Encoding.UTF8);
                //Set formatting options:
                textWriter.Formatting = Formatting.Indented; //Intented formatting
                textWriter.Indentation = 4; //Use the size of a tab to intent
                xmlSerializer.Serialize(textWriter, item);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

Skifahren in Österreich-Helmpflicht

C# to VB.Net converter, VB.Net to C# converter

Lustige Whatsapp-Bilder




SpaceX-SES-9 Start verschoben

C#/ VB.Net Bilderkennungslibrary

VB.Net/ C#.Net Datagridview Zeilenhöhen und Spaltenbreiten anpassen ohne Resize auf AllCells

VB.Net:
'Um nur die Zeilenhöhen anzupassen:
Datagridview.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders


'Um nur die Spaltenbreiten anzupassen:
Datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader

C#.Net:
//Um nur die Zeilenhöhen anzupassen:
Datagridview.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;

//Um nur die Spaltenbreiten anzupassen:
Datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;

C#.Net Datagridview Sortierung, aktuelle selektierte Zeilen und Scrollbarposition speichern




//Aktuelle Sortierung zwischenspeichern


{
    DataGridViewColumn oldColumn = Datagridview.SortedColumn;

    ListSortDirection direction = Datagridview.SortOrder;

    List<int> selectedItems = new List<int>();


    if (Datagridview.SelectedRows.Count > 0) {

        foreach (void r_loopVariable in Datagridview.SelectedRows) {
            r = r_loopVariable;
            selectedItems.Add(r.Index);

        }

    }

    //Aktuelle erste angezeigte Zeile speichern

    int saveRow = 0;


    if (Datagridview.Rows.Count > 0) {

        if ((Datagridview.FirstDisplayedCell != null)) {
            saveRow = Datagridview.FirstDisplayedCell.RowIndex;

        }

    }


'Your code




    //Sortierung anwenden


    if ((oldColumn != null)) {
        switch (direction) {

            case 0:

                break;
            case 1:

                Datagridview.Sort(oldColumn, ListSortDirection.Ascending);
                //Datagridview sortieren
                break;

            case 2:

                Datagridview.Sort(oldColumn, ListSortDirection.Descending);
                //Datagridview sortieren
                break;

        }


    } else {
        Datagridview.Sort(Datagridview.Columns(2), ListSortDirection.Descending);
        //Datagridview sortieren

    }

    //Alle SelectedRows resetten


    foreach (void r_loopVariable in Datagridview.SelectedRows) {
        r = r_loopVariable;
        r.Selected = false;

    }

    //SelectedRows wieder setzen


    if (selectedItems.Count > 0) {

        foreach (void r_loopVariable in selectedItems) {
            r = r_loopVariable;

            if (Datagridview.Rows.Count > 0) {

                if (Datagridview.Rows.Count - 1 >= r) {
                    Datagridview.Rows(r).Selected = true;

                }

            }

        }

    }

    //Scrollbar wieder richtig setzen


    if (saveRow != 0 & saveRow < Datagridview.Rows.Count) {
        Datagridview.FirstDisplayedScrollingRowIndex = saveRow;

    }
}

VB.Net Datagridview Sortierung, aktuelle selektierte Zeilen und Scrollbarposition speichern

'Aktuelle Sortierung zwischenspeichern
Dim oldColumn As DataGridViewColumn = Datagridview.SortedColumn
Dim direction As ListSortDirection = Datagridview.SortOrder
Dim selectedItems As New List(Of Integer)
If Datagridview.SelectedRows.Count > 0 Then
    For Each r In Datagridview.SelectedRows
        selectedItems.Add(r.Index)
    Next
End If
'Aktuelle erste angezeigte Zeile speichern
Dim saveRow As Integer = 0
If Datagridview.Rows.Count > 0 Then
                If Not Datagridview.FirstDisplayedCell Is Nothing Then
                               saveRow = Datagridview.FirstDisplayedCell.RowIndex
                End If
End If

 'Your Code here

'Sortierung anwenden
If Not oldColumn Is Nothing Then
    Select Case direction
        Case 0
        Case 1
            Datagridview.Sort(oldColumn, ListSortDirection.Ascending) 'Datagridview sortieren
        Case 2
            Datagridview.Sort(oldColumn, ListSortDirection.Descending) 'Datagridview sortieren
    End Select
Else
    Datagridview.Sort(Datagridview.Columns(2), ListSortDirection.Descending) 'Datagridview sortieren
End If
'Alle SelectedRows resetten
For Each r In Datagridview.SelectedRows
    r.Selected = False
Next
'SelectedRows wieder setzen
If selectedItems.Count > 0 Then
    For Each r In selectedItems
        If Datagridview.Rows.Count > 0 Then
            If Datagridview.Rows.Count - 1 >= r Then
                Datagridview.Rows(r).Selected = True
            End If
        End If
    Next
End If
'Scrollbar wieder richtig setzen
If saveRow <> 0 And saveRow < Datagridview.Rows.Count Then
    Datagridview.FirstDisplayedScrollingRowIndex = saveRow
End If

C#-Layoutdesign von Applikationen

Cooles Haibild


Fake Oracle Account

test1234567@discard.email
ayvcbas8zt267rt3qd_SADDA