none
i have a question datagridviw export to .ini file RRS feed

  • Question

  • http://www.hoons.net/Board/qacshap/Content/67073

    When I enter the URL above,

    One thing ... if I have the same key and value in the same session, can I make the section go out without repeating?

    example)
    section        key         value
    [app_info]   name        a
                   prd_name     b

                      333         555

    .ini->
    [app_info]
    name = a
    prd_name = b

    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');
                    }
                    else
                    {
                        WritePrivateProfileString(dataGridView1[0, 8].Value.ToString(), dataGridView1[1, j].Value.ToString(), dataGridView1[2, j].Value.ToString(), @'D:\MCSC_Agent.ini');
                    }
    
                }
                if(dataGridView1==null) 
                {
                    
                }
    
                MessageBox.Show('EXPORT successfully to *.INI format');
    
            }
    
            private void WriteInFile(string section,string key,string value,string path)
            {
                WritePrivateProfileString(section,key,value,path);
                if (value == null)
                {
                    throw new ArgumentException();
                }
            }
    
            private void button2_Click(object sender, EventArgs e)  //ADD_ROW Button
            {
                DataGridViewButtonColumn button = new DataGridViewButtonColumn();
                {
                    dataGridView1.Rows.Add();
                }
            }
        }
    }


    • Edited by chh.552 Tuesday, April 23, 2019 7:39 AM
    Tuesday, April 23, 2019 7:37 AM

Answers

  • Hi

    Thank you for posting here.

    For your question, you want to make the section go out without repeating if you have the same key and value in the same session.

    I think you don’t worry about it, because it could delete the duplicates automatically.

    You could refer to the following result.

    Result:

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by chh.552 Wednesday, April 24, 2019 1:11 AM
    Tuesday, April 23, 2019 8:09 AM
    Moderator