I want to fill the section value with the parent section if the section value is empty in the .ini file.

  • Thread starter Thread starter han.c.h
  • Start date Start date
H

han.c.h

Guest
Now the code is only for three pieces of data per section, and I want to have at least 10 sections, and if the grid does not have a section value, I want to have the parent section I wrote.

<section1> <section1>

key = value

key = value


key = value ->>


<section2>

key = value


key = value


key = value


->>

<section1>

key = value

key = value


key = value

key = value


key = value

<section2>

key = value


key = value


key = value

<section3>

key = value

............<section10..>

and


If you do not put a value in the section, I want the data to be entered into the data grid containing the section values.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace EXPORT
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
[DllImport('kernel32')]

public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

[DllImport('kernel32')]

public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);


public Form1()
{
InitializeComponent();
dataGridView1.AllowUserToAddRows = true; //자동 행 추가
dataGridView1.AutoGenerateColumns = false;
}

private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < dataGridView1.RowCount - 1; j++)
{
if (j < = 2)
{
WritePrivateProfileString(dataGridView1[0, 0].Value.ToString(), dataGridView1[1, j].Value.ToString(), dataGridView1[2, j].Value.ToString(), @'D:\MCSC_Agent.ini');
}
if(j >= 3)
{
WritePrivateProfileString(dataGridView1[0, 4].Value.ToString(), dataGridView1[1, j].Value.ToString(), dataGridView1[2, j].Value.ToString(), @'D:\MCSC_Agent.ini');
}

}

MessageBox.Show('EXPORT successfully to *.INI format');

}
private void button2_Click(object sender, EventArgs e) //ADD_ROW Button
{
DataGridViewButtonColumn button = new DataGridViewButtonColumn();
{
dataGridView1.Rows.Add();
}
}

//private void WriteInFile(string section, string key, string value, string path)
//{
// WritePrivateProfileString(section, key, value, path);
// if (value == null)
// {
// throw new ArgumentException();
// }
//}

Continue reading...
 
Back
Top