I need Just a Grid, Not DataGrid

  • Thread starter Thread starter Bongee
  • Start date Start date
B

Bongee

Hi,

I am developing applications using .Net C#, I am very new to this platform,

Is there any grid component ?

I couldnt manage DataGrid component, Couldnt add Rows or Columns

Thanks
 
I am developing applications using .Net C#, I am very new to this platform,

Is there any grid component ?

I couldnt manage DataGrid component, Couldnt add Rows or Columns

Could you just use a standard ListView control in Detailed view?

Cheers

Tom
 
You are correct that you cannot add rows and columns to it (directly),
however it would still probably be your best bet.

Remember that a DataGrid is really nothing but a UI for more complicated
sets of data, such as DataTables, something that you can easily add and
remove rows from at will... take the following example of a DataTable where I
create a table with 3 columns


//References
private System.Data.DataTable dataTable1;
private System.Data.DataColumn dataColumn1;
private System.Data.DataColumn dataColumn2;
private System.Data.DataColumn dataColumn3;

//Create Instances
this.dataTable1 = new System.Data.DataTable();
this.dataColumn1 = new System.Data.DataColumn();
this.dataColumn2 = new System.Data.DataColumn();
this.dataColumn3 = new System.Data.DataColumn();

//Add Columns to table
this.dataTable1.Columns.AddRange( new System.Data.DataColumn[] {
this.dataColumn1,
this.dataColumn2,
this.dataColumn3});

//Give names to the columns and table
this.dataTable1.TableName = "Table1";
this.dataColumn1.ColumnName = "Column1";
this.dataColumn2.ColumnName = "Column2";
this.dataColumn3.ColumnName = "Column3";

After that... simply create a few TextBoxes (textBox1, textBox2, and
textBox3 in this case), then you can simply do the following to add a new row
to the table based on the contents of the TextBoxes

private void AddRow_Click(object sender, System.EventArgs e)
{
this.dataTable1.Rows.Add( new object[]{
textBox1.Text,textBox2.Text,textBox3.Text });
}

And later when it comes time to remove, simply use the DataGrid to determine
which row is currently selected, and use that info to instruct the DataTable
which row to remove.

private void RemoveRow_Click(object sender, System.EventArgs e)
{
this.dataTable1.Rows.Remove( dataTable1.Rows[
this.dataGrid1.CurrentCell.RowNumber ] );
//or
this.dataTable1.Rows.RemoveAt( this.dataGrid1.CurrentCell.RowNumber );
}

Is this more of what you want to do?

Brendan
 
Hi,

First of all, are you working on a web or win app?

if web app, you have controls like the Repeater, which are easier to use. In
win app you have a ListView ( set the View to Details ) and it will looks
like a grid.


cheers,
 
Speaking of Windows Forms, a ListView cannot be databound and the OP will
have hard time making it editable (well, except for the leftmost column).
 
Hi,

Yes, but IMO all he wants to do is show data, but good annotation !

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Dmytro Lapshyn said:
Speaking of Windows Forms, a ListView cannot be databound and the OP will
have hard time making it editable (well, except for the leftmost column).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

First of all, are you working on a web or win app?

if web app, you have controls like the Repeater, which are easier to use.
In win app you have a ListView ( set the View to Details ) and it will
looks like a grid.


cheers,
 
Back
Top