Datagridview

DarKo87

Mitglied
Hallo,

Ich hab ein paar Probleme mit meinem dgv.
Folgende Klasse

Code:
    class DoubleTunerValue // t_DtList_entry
    {
        byte net;
        ushort pi;
        byte pi_received_time;
        byte net_count;
        byte no_fs_counter;
        byte no_fs_time;
        byte fs_received_counter;
        byte fs_received_time;
        byte no_pi_counter;
        byte no_pi_time;
        byte pi_received_counter;

        public ushort Pi
        {
            get { return pi; }
            set { pi = value; }
        }
        public byte Net_count
        {
            get { return net_count; }
            set { net_count = value; }
        }
        public byte No_fs_counter
        {
            get { return no_fs_counter; }
            set { no_fs_counter = value; }
        }
        public byte No_fs_time
        {
            get { return no_fs_time; }
            set { no_fs_time = value; }
        }
        public byte Fs_received_counter
        {
            get { return fs_received_counter; }
            set { fs_received_counter = value; }
        }
        public byte Fs_received_time
        {
            get { return fs_received_time; }
            set { fs_received_time = value; }
        }
        public byte No_pi_counter
        {
            get { return no_pi_counter; }
            set { no_pi_counter = value; }
        }
        public byte No_pi_time
        {
            get { return no_pi_time; }
            set { no_pi_time = value; }
        }
        public byte Pi_received_counter
        {
            get { return pi_received_counter; }
            set { pi_received_counter = value; }
        }
        public byte Pi_received_time
        {
            get { return pi_received_time; }
            set { pi_received_time = value; }
        }
    }

Davon möchte ich aber nicht alles in dem dgv anzeigen lassen sondern nur z.B. net und pi.
Finde aber keine Lösung dazu, kann mir vielleicht jemand helfen?

Gruß
 
Hallo,

du kannst für jede Spalte im DGV die Sichtbarkeit ein- oder ausschalten.
C#:
dataGridView1.Columns[0].Visible = false;

Vielleicht reicht dir das ja schon.
 
Vielen Dank, ja das hat schon geholfen!

Nun hab ich ein weiteres Problem, ich möchte folgende liste an ein dgv binden.
Code:
private List<ushort> ticTCM = new List<ushort>(); // TIC TCM
dataGridView1.DataSource = dc.TICTCM;

Leider bleibt in dem fall, das dgv aber leer. Obwohl es vom Board aus gefüllt wird.

Gruß
 
Hallo,

das könntest du so machen:
C#:
List<ushort> ticTCM = new List<ushort>();
BindingSource source = new BindingSource();
dataGridView2.DataSource = source;
ticTCM.Add(1);
ticTCM.Add(2);
ticTCM.Add(3);
ticTCM.Add(4);
ticTCM.Add(5);

source.DataSource = ticTCM.Select(x => new { Value = x }).ToList();
            
// später neues Element hinzufügen
ticTCM.Add(6);
// nach dem hinzufügen, Binding Source updaten und damit auch das DGV
source.DataSource = ticTCM.Select(x => new { Value = x }).ToList();
 
Hallo,

das könntest du so machen:
C#:
List<ushort> ticTCM = new List<ushort>();
BindingSource source = new BindingSource();
dataGridView2.DataSource = source;
ticTCM.Add(1);
ticTCM.Add(2);
ticTCM.Add(3);
ticTCM.Add(4);
ticTCM.Add(5);

source.DataSource = ticTCM.Select(x => new { Value = x }).ToList();
            
// später neues Element hinzufügen
ticTCM.Add(6);
// nach dem hinzufügen, Binding Source updaten und damit auch das DGV
source.DataSource = ticTCM.Select(x => new { Value = x }).ToList();

Danke, das sieht ziemlich gut aus. Allerdings bekomme ich das nicht zum laufen. Kann es sein das gewisse sachen in VS05 noch nicht verfügbar waren?

Gruß
 
Hallo,

ja das select ist da wohl etwas neuer. ;-)
Dann musst du den Umweg über ein Objekt gehen.

Hier mal examplarisch:

C#:
class MyShort
{
     public ushort US { get; set; }      // Wir speichern deinen shortwert in dieser Klasse...      
}

List<ushort> ticTCM = new List<ushort>();
BindingSource source = new BindingSource();
dataGridView2.DataSource = source;

ticTCM.Add(1);
ticTCM.Add(2);
ticTCM.Add(3);
ticTCM.Add(4);
ticTCM.Add(5);

List<MyShort> shortList = new List<MyShort>();

//speichern deiner ushort Values in der MyShort Liste.
foreach (ushort us in ticTCM)
{
    MyShort s = new MyShort();
    s.US = us;
    shortList.Add(s);
}

source.DataSource = shortList;

// Da wäre dann wirklich besser deine ushort Liste zu löschen und gegen eine "Objektliste" zu tauschen.
 

Neue Beiträge

Zurück