Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ProgressBar im DataGridView? (C#)

Empfohlene Antworten

Veröffentlicht

Ist es möglich unter Visual C# (VS2010) eine ProgressBar in ein DataGridView einzubinden und diese dann Individuell nach Spalte zu "Kontrollieren"?

----------------------------------------------------------------------------

Danke schonmal für eure Antworten

  • Autor

OK dann führe ich es ein wenig genauer aus.

Also, ich bin immoment dabei ein Programm zu schreiben welches die Sessions einer Oracle-Datenbank anzeigt.(Grob gesagt)

Ich möchte nun bei Langzeitprozessen eine ProgressBar anzeigen wielange diese noch dauern.

Herauszufinden welche Langops. sind und welche nicht, mache ich im Programm noch aber ich weiß nicht wie ich nun eine/mehrere ProgressBars ins GridView kriege.

Ich glaube ich hab mal gelesen das man nen Array machen kann (anzahl muss gleich sein der Rows die man hat) und diesen dann einfach "einfügen" kann.

Hoffe das hilft ein wenig.

  • Autor

soo habe wie im obigen beitrag erwähnt mich an dem Beispiel Code von Mark Rideout gehängt, jedoch die Paint methode von einem anderen User genommen (Damit es wie ne echte PGBar aussieht^^). Ich mache es jetzt so das ich mir die Werte gleich beim Statement berechnen lasse und mir die Prozentzahl wiedergebe (also Datengebunden). Hier mal der code der beiden Klassen:

Klasse1:

using System;

using System.Windows.Forms;

using System.Drawing;

using System.ComponentModel;


namespace DBSessions

{

    class DataGridViewProgressCell : DataGridViewImageCell 

    {

        // Used to make custom cell consistent with a DataGridViewImageCell

        static Image emptyImage;

        static DataGridViewProgressCell()

        {

            emptyImage = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        }

        public DataGridViewProgressCell()

        {

            this.ValueType = typeof(int);

        }


        // Method required to make the Progress Cell consistent with the default Image Cell.

        // The default Image Cell assumes an Image as a value, although the value of the Progress Cell is an int.

        protected override object GetFormattedValue(object value,

                            int rowIndex, ref DataGridViewCellStyle cellStyle,

                            TypeConverter valueTypeConverter,

                            TypeConverter formattedValueTypeConverter,

                            DataGridViewDataErrorContexts context)

        {

            return emptyImage;

        }


        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds,

            int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText,

            DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)

        {

            int progressVal;

            if (value != null)

            {

                progressVal = (int)value;

            }

            else

            {

                progressVal = 1;

            }


            float percentage = ((float)progressVal / 100.0f); 


            Brush backColorBrush = new SolidBrush(cellStyle.BackColor);


            Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);


            // Draws the cell grid


            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));


            const int margin = 4;


            ProgressBar pb = new ProgressBar();


            pb.Height = cellBounds.Bottom - cellBounds.Top - (margin * 2);


            pb.Width = cellBounds.Right - cellBounds.Left - (margin * 2);


            pb.Value = progressVal;


            Bitmap bmp = new Bitmap(pb.Width, pb.Height);


            pb.DrawToBitmap(bmp, pb.ClientRectangle);


            g.DrawImage(bmp, new Point(cellBounds.X + margin, cellBounds.Y + margin));


        }

    }

}
Klasse2:
using System.Windows.Forms;


namespace Sample{

    public class DataGridViewProgressColumn : DataGridViewImageColumn

    {

        public DataGridViewProgressColumn()

        {

            CellTemplate = new DataGridViewProgressCell();

        }

    }

}

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.