Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

switch rows and columns in a datagridview

DataTable oldTable = new DataTable();

...

DataTable newTable = new DataTable();

newTable.Columns.Add("Field Name");
for (int i = 0; i < oldTable.Rows.Count; i++)
    newTable.Columns.Add();

for (int i = 0; i < oldTable.Columns.Count; i++)
{
    DataRow newRow = newTable.NewRow();

    newRow[0] = oldTable.Columns[i].Caption;
    for (int j = 0; j < oldTable.Rows.Count; j++)
        newRow[j+1] = oldTable.Rows[j][i];
    newTable.Rows.Add(newRow);
}

dataGridView.DataSource = newTable;
Comment

PREVIOUS NEXT
Code Example
Csharp :: == vs equals c# 
Csharp :: unknown discriminator value mongodb 
Csharp :: save current dir shell 
Csharp :: quartz .net core execute controller 
Csharp :: c# short 
Csharp :: generate jwt token authorize(roles = admin ) not working .net core 403 
Csharp :: c# check if pdf is protected without password 
Csharp :: c# inject dll into process 
Csharp :: WPF combobox filter as you type 
Csharp :: DataTable GetErrors 
Csharp :: unity disable the display of the camera frustrum 
Csharp :: c# ClassMap 
Csharp :: object escape player unity 
Csharp :: how to make character respawn if touches sprite c# 
Csharp :: username and password into base64 encoding c# 
Csharp :: c# void with nullable List argument 
Csharp :: Request ID: XPBBR4XG1UWuX6fWF08_-jzYkrommVJjO7Os50CTYuZmiw7kMsFUkw== 
Csharp :: C# walk down a tree and back 
Csharp :: unity download image from online 
Csharp :: wpf string to byte array 
Csharp :: worsening 
Csharp :: mesh data optimization resolving used channels 
Csharp :: create expression func c# for use in where clause 
Csharp :: c# exec command output 
Csharp :: CharacterController 
Csharp :: generate an mvc controller when dotnet core command line 
Csharp :: umbraco cannot start. a connection string is configured but umbraco cannot connect to the database. 
Csharp :: PUN 2 Network Transform View Jittery Movement 
Csharp :: jtoken value is not exact double 
Csharp :: ef core totable 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =