none
how to datagridviiew data in .ini file export RRS feed

  • Question

  • I want to export the .ini file to the grid with the section, key, and value values shown in the example above.

    example)

    [app_info]

    a = 1

    b= asd

    [main_info]

    v=asdas

    cs=dsd

    Monday, April 22, 2019 8:23 AM

All replies

  • Hello,

    There are no straight ways to read an ini file, see the following post for several methods to read them.

    https://stackoverflow.com/questions/217902/reading-writing-an-ini-file 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, April 22, 2019 9:22 AM
    Moderator
  • http://www.hoons.net/Board/qacshap/Content/67073

    When I enter the URL above, I try to put data into the grid and press the export button to save it as an .ini file in the form of section, key, value. What should I do?

    Monday, April 22, 2019 11:26 PM
  • http://www.hoons.net/Board/qacshap/Content/67073

    When I enter the URL above, I try to put data into the grid and press the export button to save it as an .ini file in the form of section, key, value. What should I do?  Inside the code, the content is created as an ini file, but not as a grid.

    Monday, April 22, 2019 11:43 PM
  • Hi

    Thank you for posting here.

    For your question, you want to export the .ini file to the datagridview.

    You could try the following code, please note that I used INI Parser from NuGet packages.

    private void Form1_Load(object sender, EventArgs e)
            {
                IniParser parser = new IniParser(@"D:\test.ini");
    
                string value1= parser.GetSetting("app_info", "a");
                string value2 = parser.GetSetting("app_info", "b");
                string value3 = parser.GetSetting("main_info", "v");
                string value4 = parser.GetSetting("main_info", "cs");
                DataTable table = new DataTable();
                table.Columns.Add("Section", typeof(string));
                table.Columns.Add("key", typeof(string));
                table.Columns.Add("value", typeof(string));
    
                // Here we add five DataRows.
                table.Rows.Add("app_info", "a", value1);
                table.Rows.Add("app_info", "b", value2);
                table.Rows.Add("main_info", "v", value3);
                table.Rows.Add("main_info", "cs", value4);
                dataGridView1.DataSource = table;        
        }
    

    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.

    Tuesday, April 23, 2019 2:11 AM
    Moderator
  • i want to see the generated ini file by putting it in the datagridview and pressing the export button instead of putting section,...NOT IN CODE


    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);
            static string path = 'C:\\Test.ini';
            public Form1()
            {
                InitializeComponent();
                dataGridView1.AllowUserToAddRows =true; //자동 행 추가
                dataGridView1.AutoGenerateColumns = false;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                WritePrivateProfileString('SECTION', 'KEY', 'VALUE', @'C:\ConnectionInfo.ini');
                MessageBox.Show('EXPORT successfully to *.INI format');
               
    
            }
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
    
            }
            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 4:54 AM
    Tuesday, April 23, 2019 4:00 AM
  • Hi

    I have answered your question in this thread

    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.

    Tuesday, April 23, 2019 7:50 AM
    Moderator
  • i am a question....

    msdn[How do I get the data in the .ini file variable by section?]

    i made .ini 

    maybe section 10~20 data

    ex

    <section1>

    key = value

    key = value

    key = value

    key = value

    <section2>

    key = value

    key = value

    key = value

    key = value

    key = value

    <section3>

    key = value

    Wednesday, April 24, 2019 6:08 AM
  • Hi

    We will solve your question in this thread as soon as possible.

    Please wait patiently.

    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.

    Wednesday, April 24, 2019 6:16 AM
    Moderator
  • thank you.plesae code remark..nn
    Wednesday, April 24, 2019 6:29 AM
  • are you finished? jack j jun.. n_n
    Wednesday, April 24, 2019 11:23 PM
  • Hi

    Thanks for the feedback.

    It seems that your question has been replied by somebody. If you have any question in that problem, you could give some feedback in this thread.  

    Our team will solve your question in this thread as soon as possible.

    Note: This thread has been closed, If you have any question about c#, you could create a new thread in c# forum.

    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.


    Thursday, April 25, 2019 2:24 AM
    Moderator
  • thank you for support.

    i am a quesiton .i'm create a forum.  [i want to file the section value with the partent section if the section value is empty in the .ini file.] please contact.



    https://social.msdn.microsoft.com/Forums/vstudio/en-US/abd8ab7d-700d-4800-82ae-60bbdef69645/i-want-to-fill-the-section-value-with-the-parent-section-if-the-section-value-is-empty-in-the-ini?forum=csharpgeneral
    • Edited by chh.552 Thursday, April 25, 2019 2:56 AM
    Thursday, April 25, 2019 2:53 AM
  • i'm create new thread.

    thread name -> i would like to have the data in the data grid view if the section is blank,as shown in the url[image][import .ini]

    Friday, April 26, 2019 12:07 AM
  • Hi

    Thanks for the feedback.

    I have viewed this thread. I think it is hard to achieve. Because each time you use the WritePrivateProfileString method, you will add the values of the three attributes section, key, and value. But when the ini file detects that the key and value use the same section, the ini file will cancel the duplicate section by default. Therefore, I think it can not to achieve.

    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.

    Friday, April 26, 2019 6:43 AM
    Moderator