0

Hi Guys,

I'm currently working on a small item that I hope you will be able to help with. I have used an example Code to get connected to 'Sage Line 50' data and it seems to work correct. Currently it populates the Combo Box with the Database Scheme and from there depending on what is selected will show the contents of the table in the List View.

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;

namespace SageConnection2012
{
    public partial class Form1 : Form
    {
        private ADODB.Connection adoConn = new ADODB.Connection();
        private ADODB.Recordset adoRS = new ADODB.Recordset();

        public Form1()
        {
            InitializeComponent();

            adoConn.Open("SageLine50v17", "Manager", "", 0);

            adoRS = adoConn.OpenSchema(ADODB.SchemaEnum.adSchemaTables, null, System.Reflection.Missing.Value);




            while (!(adoRS.EOF))
            {
                comboBox1.Items.Add(adoRS.Fields["TABLE_NAME"].Value.ToString());

                adoRS.MoveNext();
            }

            adoRS.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strSelect = null;
            ListViewItem LvItem = default(ListViewItem);

            const int adCmdText = 1;

            strSelect = "Select * FROM SALES_LEDGER";
            adoRS.Open(strSelect, adoConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic, adCmdText);

            if (adoRS.EOF == false) {

                adoRS.MoveFirst();

                lvMain.Clear();
                lvMain.View = View.Details;

                for (int i = 0; i <= adoRS.Fields.Count - 1; i++)
                {
                    lvMain.Columns.Add(adoRS.Fields[i].Name, 100);
                }


                lvMain.BeginUpdate();

                do
                {
                    LvItem = new ListViewItem();

                    LvItem.Text = Convert.ToString(adoRS.Fields[0].Value);

                    for (int i = 1; i <= adoRS.Fields.Count - 1; i++)
                    {
                        try
                        {
                            LvItem.SubItems.Add(Convert.ToString(adoRS.Fields[i].Value));
                        }
                        catch
                        {
                            LvItem.SubItems.Add(" ");
                        }

                    }

                    lvMain.Items.Add(LvItem);
                    adoRS.MoveNext();


                } while (!(adoRS.EOF == true));

                lvMain.EndUpdate();

                adoRS.Close();
            }
            else
            {
                lvMain.Clear();
                adoRS.Close();
            }
            lvMain.Focus();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

    }
}

My issue now is I need to kind of get rid of the Combo Box and just show the 'Sales_Ledger' table within the List view when a radio button is clicked. Also, I need to show particular columns in the list view. Acc_Name, CITY etc.

any helpe would be great on this! Thanks a million guys!

Mark.

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by lolafuertes
0

Instead of using the numeric index for the fields, you can use the field name to get a particular field. So instead of adding all the fields, you should determine, one by one, wich of them are to be added as subitems in the ListView.

I'll suggest to entirely move the presentation of the ListView into an independent procedure that can be called from any 'thrower'. In your case, callit from the radio button checked change event, when the checked state is true.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.