Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guy i Need your help please. I collect my data from database througth DataTable dt1 after it i choice wich Column i will add in my new Object DataTable dt2 and than i just Need to Transfer avlues of my dt2 on to datagridview. like you can see Hier in Code.
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;
using System.Threading;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Reflection;

amespace Kommissionierung
{
     public static class __DataRequest
    {
        private static string rowValue = "";
        private static string Status;
        private static string ArtikelNr;
        private static int index = 0;
        private static string Mitarbeiter;
        private static string ArtikelName;
        private static bool result = true;
        private static string prioritaet;
       private static DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();


 public static DataTable KommissionAktualisieren(DataGridView dg)
{  DataTable dt = new DataTable();
    using (SqlConnection connection = new SqlConnection())
    {
   connection.ConnectionString = Properties.Settings.Default.KomissionierungDemoConnectionString;
 DataSet ds = new DataSet();
 SqlDataAdapter da = new SqlDataAdapter(
            try
            {
 da.SelectCommand = new SqlCommand("SELECT * FROM V_KommissionAnsicht ", connection);
   ds.Clear();
    da.Fill(ds);
    dt = ds.Tables[0];
    DataTable dt2 = new DataTable();
    DataRow row;


   foreach (DataTable dts in ds.Tables)
   {
     foreach (DataRow dr in dts.Rows)
      {
        row = dt2.NewRow();
        ArtikelNr = dr.ItemArray[2].ToString();
        Status = dr.ItemArray[4].ToString();
        Mitarbeiter = dr.ItemArray[3].ToString();
        prioritaet = dr.ItemArray[5].ToString();

        if (dt2.Columns.Contains("Artikel") == false)
        {
          chk.Name = "checked";
          chk.HeaderText = "Text";
         chk.Resizable = DataGridViewTriState.False;  
         dg.Columns.Add(chk);
         dt2.Columns.Add("Artikel");
        }

       if (dt2.Columns[0].ToString() == "Artikel")
        {
           row["Artikel"] = dr.ItemArray[1].ToString();
           ArtikelName = row["Artikel"].ToString();

            }

          if (dt2.Columns.Contains("ArtikelNr") == false)
        {
           dt2.Columns.Add("ArtikelNr");
        }

         if (dt2.Columns[1].ToString() == "ArtikelNr")
           {
              row["ArtikelNr"] = dr.ItemArray[2].ToString();
           }
         if (dt2.Columns.Contains("Prioritaet") == false)
           {
            dt2.Columns.Add("Prioritaet");
           }
         if (dt2.Columns[2].ToString() == "Prioritaet")
         {
           row["Prioritaet"] = dr.ItemArray[5].ToString();
         }
     }
  }
 }


I have a Problem please. on my DataGridView i want to get a HeaderText of my Columns on the Vertical.

has somebody an idea?
Beside to get a column like this
|Col1|Col2|
I Need to get it like this

|C|C|
|o|o|
|l | l|
|1|2|
Posted
Comments
avikGhosh87 18-Jul-13 5:12am    
what you actually want, the header text value you want to show is it a single value ,return for all row??
stefan from germany 18-Jul-13 5:44am    
yes

1 solution

 
Share this answer
 
Comments
johannesnestler 18-Jul-13 5:42am    
I wanted to link the same site 3 mins after you - so I upvoted yours ;-)
stefan from germany 18-Jul-13 5:50am    
thx Nasir this link help me a lot. and resolve correctly my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900