Autor Beitrag
Ivy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Di 21.02.12 12:04 
Guten Morgen,
ich möchte gerne die erste Zeile aus meiner datagridview in einen string ausgelesen haben (nicht in ein array).... wie kann ich auf die erste zeile zugreifen, sodass ich einen zusammenhängenden daten-string herausbekomme?!
z.b
string = "Wert1,wert2,wert3"

LG
IVY
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.02.12 12:07 
Ich glaube nicht, dass es das fertig gibt (habe ich bisher jedenfalls nichts von gesehen). Die kleine Schleife wirst du vermutlich selbst implementieren müssen. ;-)
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Di 21.02.12 12:18 
mhm ich habe es mal mit einer arraylist realisiert aus einer datatable ...da sieht es so aus. kann ich es nicht aus meiner datatable ähnlich machen, dass ich einen string bekomme sattt dem array?

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 ArrayList myArrayList = new ArrayList();
         for (int i = 0; i <= datatable.Rows.Count - 1; i++)
        {
             for (int j = 0; j <= datatable.Columns.Count - 1; j++)
              {     
            myArrayList.Add(datatable.Rows[i][j].ToString());
            }
         }
       return myArrayList;
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Di 21.02.12 12:43 
Hallo Ivy

Ich habs mal ausprobiert:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
String text = "";
            foreach (DataGridViewColumn column in dataGridView1.Columns)
            {
                text += dataGridView1.Rows[0].Cells[column.Index].Value.ToString() + " ";
            }
            MessageBox.Show(text);

Müsste funktionieren.

_________________
Gruss
mats74
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 21.02.12 13:46 
ausblenden C#-Quelltext
1:
string ersteZeileInDataTableAlsKommaSeparierterString = string.Join(",", datatable.Rows[0].ItemArray.Select(x => Convert.ToString(x)));					
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Di 21.02.12 14:14 
super habe mats beispiel angewendet und funktioniert ;-)
danke...