Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
GeneralRe: Showing legacy data in data grid Pin
Anonymous5-May-05 5:16
Anonymous5-May-05 5:16 
GeneralRe: Showing legacy data in data grid Pin
dirk helmet5-May-05 5:41
sussdirk helmet5-May-05 5:41 
GeneralRe: Showing legacy data in data grid Pin
keith maddox5-May-05 6:58
keith maddox5-May-05 6:58 
GeneralRe: Showing legacy data in data grid Pin
dirkhelmet5-May-05 7:43
dirkhelmet5-May-05 7:43 
GeneralRe: Showing legacy data in data grid Pin
keith maddox5-May-05 9:10
keith maddox5-May-05 9:10 
GeneralRe: Showing legacy data in data grid Pin
dirk helmet5-May-05 9:26
sussdirk helmet5-May-05 9:26 
GeneralRe: Showing legacy data in data grid Pin
keith maddox5-May-05 10:08
keith maddox5-May-05 10:08 
GeneralRe: Showing legacy data in data grid Pin
keith maddox5-May-05 12:40
keith maddox5-May-05 12:40 
Okay, here is some sample code. Sorry it's not real orderly but I just don't have time to make it real nice. I think you'll get the idea though. this code will populate a datagrid with three columns times x rows (just an exmaple, you could have as many columns as you like) from a mock of
what I think your API looks like.


Here is the form
---------------------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace SampleOfIList {

///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form {

private System.Windows.Forms.DataGrid dataGrid1;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1() {
InitializeComponent();
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(640, 160);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(656, 197);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main() {
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e) {
dataGrid1.DataSource = new MyIListImpl(new SomeAPI());
// to-do:
// use table column styles to set the order of the columns or else they are
// kind of random.
}
}
}

-------------------------------------------------------------------------------------

here is the sample API (hopefully similar to yours)

using System;

namespace SampleOfIList {

///
/// Just a little mock API with some test data stuffed in. Hopefully not
/// too different from yours but you should get the idea anyway.
///

public class SomeAPI {


// Some place to put mock data
private string[,] internalList;


///
/// ctor and stuff some dummy data in there for illustration only.
/// We'll make it 3x3 for demo purposes.
///

public SomeAPI() {
internalList = new string[3,3];
internalList[0,0] = "r0c0";
internalList[0,1] = "r0c1";
internalList[0,2] = "r0c2";
internalList[1,0] = "r1c0";
internalList[1,1] = "r1c1";
internalList[1,2] = "r1c2";
internalList[2,0] = "r2c0";
internalList[2,1] = "r2c1";
internalList[2,2] = "r2c2";
}


///
/// This is how the outside world can get at our mock data. Similar to your
/// example API.
///

/// <param name="row" />
/// <param name="column" />
/// <returns>
public string GetData(int row,int column) {
return internalList[row,column];
}


///
/// How many rows in the mock data.
///

public int numRows {
get {
return internalList.GetUpperBound(0)+1;
}
}


}

}

-------------------------------------------------------------------------------------------
here is the IList impl

using System;
using System.Collections;
using System.Data;

namespace SampleOfIList {

///
/// An intermediate row object so the grid can deal with it.
///

public struct Row {

public Row(string s1,string s2,string s3) {
c1 = s1;
c2 = s2;
c3 = s3;
}

public string COL_0 {
get { return c1; }
set { c1 = value; }
}

public string COL_1 {
get { return c2; }
set { c2 = value; }
}

public string COL_2 {
get { return c3; }
set { c3 = value; }
}

private string c1;
private string c2;
private string c3;
}


///
/// Implemented the hard way just for illustration, but this is an IList object
/// which supplies the datagrid with data. Just set the DataGrid.DataSoruce member
/// and away it goes.
///

public class MyIListImpl : IList {

private SomeAPI api = null;

public MyIListImpl(SomeAPI api) {
this.api = api;
}

void ICollection.CopyTo(Array arr,int index) {
throw new ArgumentException("CopyTo - Not implemented");
}

int ICollection.Count {
get {
return api.numRows;
}
}

bool ICollection.IsSynchronized {
get {
throw new ArgumentException("IsSynchronized - Not implemented");
}
}

object ICollection.SyncRoot {
get {
throw new ArgumentException("SyncRoot - Not implemented");
}
}

IEnumerator IEnumerable.GetEnumerator() {
throw new ArgumentException("GetEnumerator - Not implemented");
}

int IList.Add(object obj) {
throw new ArgumentException("Add - Not implemented");
}

void IList.Clear() {
throw new ArgumentException("Clear - Not implemented");
}

bool IList.Contains(object o) {
throw new ArgumentException("Contains - Not implemented");
}

int IList.IndexOf(object o) {
throw new ArgumentException("IndexOf - Not implemented");
}

void IList.Insert(int ix,object o) {
throw new ArgumentException("Insert - Not implemented");
}

bool IList.IsFixedSize {
get {
return true;
}
}

bool IList.IsReadOnly {
get {
return true;
}
}

void IList.Remove(object o) {
throw new ArgumentException("Remove - Not implemented");
}

void IList.RemoveAt(int ix) {
throw new ArgumentException("RemoveAt - Not implemented");
}


///
/// Here is the meat of the thing!
///

object IList.this[int ix] {
get {
Row row = new Row(api.GetData(ix,0),api.GetData(ix,1),api.GetData(ix,2));
return row;
}
set {
throw new ArgumentException("Indexer//Set - Not implemented");
}
}

}

}



--------------------------------------------------------------------------------------


hope that helps.
GeneralControl access from other classes Pin
DJNokturnal5-May-05 3:43
DJNokturnal5-May-05 3:43 
GeneralRe: Control access from other classes Pin
MoustafaS5-May-05 4:27
MoustafaS5-May-05 4:27 
GeneralRe: Control access from other classes Pin
DJNokturnal6-May-05 5:53
DJNokturnal6-May-05 5:53 
Generaluse one C# exe method to another C# Project Pin
joy_priyank5-May-05 1:46
joy_priyank5-May-05 1:46 
GeneralRe: use one C# exe method to another C# Project Pin
MoustafaS5-May-05 1:58
MoustafaS5-May-05 1:58 
GeneralRe: use one C# exe method to another C# Project Pin
joy_priyank5-May-05 2:28
joy_priyank5-May-05 2:28 
GeneralRe: use one C# exe method to another C# Project Pin
ChesterPoindexter5-May-05 3:34
professionalChesterPoindexter5-May-05 3:34 
GeneralRe: use one C# exe method to another C# Project Pin
MoustafaS5-May-05 4:18
MoustafaS5-May-05 4:18 
GeneralMoving huge amounts of Data over Local/Lan Pin
Sharpoverride5-May-05 1:33
Sharpoverride5-May-05 1:33 
GeneralRe: Moving huge amounts of Data over Local/Lan Pin
keith maddox5-May-05 5:58
keith maddox5-May-05 5:58 
GeneralRe: Moving huge amounts of Data over Local/Lan Pin
Sharpoverride6-May-05 1:50
Sharpoverride6-May-05 1:50 
GeneralVS .NET Server Explorer Add-in Pin
rsdouglas5-May-05 1:22
rsdouglas5-May-05 1:22 
GeneralDefault values for properties Pin
WujekSamoZlo4-May-05 23:35
WujekSamoZlo4-May-05 23:35 
GeneralRe: Default values for properties Pin
Stefan Troschuetz5-May-05 0:34
Stefan Troschuetz5-May-05 0:34 
GeneralRe: Default values for properties Pin
Maqsood Ahmed5-May-05 0:35
Maqsood Ahmed5-May-05 0:35 
Generalcombo box in datagrid Pin
steve_rm4-May-05 22:17
steve_rm4-May-05 22:17 
GeneralRe: combo box in datagrid Pin
MoustafaS5-May-05 0:50
MoustafaS5-May-05 0:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.