Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

programicly add custom lines in before the program populates listbox

$
0
0

ok i have a program that i am trying to add lines in before program loads or populates the listbox 

issue being im not sure how to add custom lines on listbox i tryied using find for listboxT witch is in the search fuction of this code here

        string temp;
        string[] tempsplit;
        string file_path;
        string file_name;
        string anims_to_find = "idleAnim";

        struct KVP
        {
            public KVP(string k, string v )
            {
                key = k;
                value = v;
            }

            public string key { get; set; }
            public string value { get; set; }

        }

        List<KVP> kvps = new List<KVP>();
        List<Exception> exs = new List<Exception>();
        public Form1()
        {
            InitializeComponent();
        }


        public void search()
        {
            //MessageBox.Show("");
            KVP elfkvp = kvps.Find(x => x.key.Contains("gunModel"));
            kvps.Add(new KVP(elfkvp.key, elfkvp.value = "1234"));


        }

        bool ParseWeaponFile(string path_name)
        {
            
            using (StreamReader sr = new StreamReader(path_name))
            {

                temp = sr.ReadToEnd();
                if (!temp.Contains("WEAPONFILE"))
                {
                    MessageBox.Show("Invalid file selected", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
                else
                {
                    tempsplit = temp.Split('\\');
                    for (int i = 1; i < tempsplit.Length - 1; i += 2)
                    {

                        kvps.Add(new KVP(tempsplit[i], tempsplit[i + 1]));
                    }
                    return true;
                }
            }
        }

        void PopulateView()
        {
            search();
            foreach (KVP item in kvps)
            {
                string[] row = { item.key, item.value };
                var list_view_item = new ListViewItem(row);
                kvpView.Items.Add(list_view_item);
            }

            foreach (ColumnHeader header in kvpView.Columns)
            {
                header.Width = -2;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            modifySelectedToolStripMenuItem.Enabled = kvpView.SelectedItems.Count > 0;
        }

        private string ConstructWeaponFile(ListView.ListViewItemCollection items)
        {
            if (kvps.Count <= 0)
            {
                MessageBox.Show("Nothing to save!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return null;
            }

            string contents = "WEAPONFILE\\";

            foreach (ListViewItem item in kvpView.Items)
                contents += string.Format("{0}\\{1}\\", item.SubItems[0].Text, item.SubItems[1].Text);
            return contents;
        }

        private string ConstructGDTEntry(ListView.ListViewItemCollection items)
        {
            if (kvps.Count <= 0)
            {
                MessageBox.Show("Nothing to save!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return null;
            }
            string contents = string.Empty;
            contents = string.Format("\t\"{0}\" ( \"bulletweapon.gdf\" ) \n\t{{\n\t\t\"configstringFileType\" \"WEAPONFILE\"\n\t\t\"targetFolder\" \"2: Multi-Player\"\n", file_name);

            foreach (ListViewItem item in kvpView.Items)
                contents += string.Format("\t\t\"{0}\" \"{1}\"\n", item.SubItems[0].Text, item.SubItems[1].Text);

            contents += "\t}";
            return contents;
        }

        private void SaveToNew(string contents, string filter = "")
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                if (filter == "")
                    sfd.Filter = "All Files (*.*)|*.*";
                else
                    sfd.Filter = filter;

                if (sfd.ShowDialog() != DialogResult.OK || sfd.FileName == "")
                    return;

                File.WriteAllText(sfd.FileName, contents);
            }
        }


as you can see form here im trying to edit gunmodel i need to edit loads of values before the listbox loads or after it loads and refresh it but not sure how to go about editing values and keys on list 

        public void search()
        {
            //MessageBox.Show("");
            KVP elfkvp = kvps.Find(x => x.key.Contains("gunModel"));
            kvps.Add(new KVP(elfkvp.key, elfkvp.value = "1234"));


        }

this is what i have tryied 

thanks in advance elfenliedtopfan5


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>