Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

populating combobox problem

helloisehelloise Posts: 2Member
i have a third party combobox and is bound to the stocklocationBindingSource's location field. however because it is a thirdparty component,devexpress they advised that i populate the combobox manually because by just binding it, it only shows the first row in the table.
now: i have about 100 comboboxes and thought it best to have the code in a seperate class and the call that class and pass the parameters using a constructor...but not sure how to go about it. i have the following:
[code][/code]namespace WinUI.Forms.BackOffice
{
using WinUI.DataSets;
using WinUI.DataAccessLayers;
using WinUI.HelperClasses;

public partial class frmItemMaintenance : frmButtons
{
public frmItemMaintenance()
{
InitializeComponent();
CenterToScreen();
btnOk.Hide();
}

private void frmItemMaintenance_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'stockLocationData.STOCKLOCATION' table. You can move, or remove it, as needed.


// TODO: This line of code loads data into the 'itemData.ITEMMASTER' table. You can move, or remove it, as needed.
//comboBoxEditLocation.DataSource = stockLocationData.Tables[0];
//comboBoxEditLocation.DisplayMember = "Location";


GetComboBoxRows getRows = new GetComboBoxRows(stockLocationData, comboBoxEditLocation,"Location",0);
}
}
}
[code][/code]



and then my manual code to populate:
[code][/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.Configuration;
using System.IO;
using System.Data.SqlClient;

namespace WinUI.HelperClasses
{
class GetComboBoxRows
{
private DataSet dsLocal;
private DevExpress.XtraEditors.ComboBoxEdit comboBoxLocal;
private string table;
int rowLocal;

//contructor
public GetComboBoxRows(DataSet ds,DevExpress.XtraEditors.ComboBoxEdit name,string tableName,int rowno)
{
dsLocal = ds;
comboBoxLocal = name;
table = tableName;
rowLocal = rowno;
}

public void GetRows()
{
foreach (DataTable dt in dsLocal.Tables)
{
int i = 0;
foreach (DataRow dr in dt.Rows) //loop through rows
{
comboBoxLocal.Properties.Items.Add(dsLocal.Tables[0].Rows[i][table]);
i++;
}
}

}
}
}
[code][/code]






Sign In or Register to comment.