LoginSignup
0
0

More than 5 years have passed since last update.

Visual Studio / Windows Forms Application > DataGridView > XE4:TStringGridに相当する / csv文字列を代入: .split()使用

Last updated at Posted at 2017-04-21
動作環境
Visual Studio 2017 Community (以下VS)
Windows 7 Pro (32bit)

C++ Builder XE4でのTStringGridのような表を作りたい。

VSではDataGridViewというものらしい。
https://code.msdn.microsoft.com/windowsapps/WindowsForm-howto-886e7d03

Addしてみた

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _170421_helloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Add("data1", "data2", "data3");
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

work.png

csv文字列を代入

参考: http://qiita.com/7of9/items/3514fe24dad36a1afe50

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _170421_helloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string alist = "data1,data2,data3";
            string[] elem = alist.Split(',');
            dataGridView1.Rows.Add(elem[0], elem[1], elem[2]);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

.Rows.Add()の部分には改善の余地はある。

dataGridView1.Rows.Add(elem);でも追加できた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0