BexM

Hello

I am relatively new to windows development, and for some reason I am finding that the things I found unbelievably simple in web, I can work out for windows.

I have a datagridview and a dataset that I want to bind to it.

I know how to go Datagridview.datasource = my dataset and then datagridview.databind();
This will display all columns in the gridview, but I want to set the order of the columns and manipulate some of the columns value.

In web I would do something like this for each column in the HTML:

<%# DoTranslation(DataBinder.Eval(Container.DataItem, "StatusName") ) %>

This will take the statusname and then send it to a custom function and translate it..

How on earth do I do something similar in windows
Please give me a full example of binding to a grid, or send me in the direction of something that will help

I don't want to use the datasource object.

Bex



Re: Windows Forms General Setting the value of a DataGridView Column

Fábio

Since you are new to DataGridView, you better run into a tutorial. DataGridView is a great control, but some people may get overwhelmed by its functionalities, here is a good tutorial for you:

http://www.devx.com/dotnet/Article/33748 type=kbSampleProd&trk=MSCP

Hope this helps.

Regards,

Fabio






Re: Windows Forms General Setting the value of a DataGridView Column

BexM

Thanks for the tutorial..!

Unfortunately I am still none the wiser on how to do what I am asking above. Can I use a "Databinder.Eval" type thing on it





Re: Windows Forms General Setting the value of a DataGridView Column

Fábio

Not on Windows Forms.






Re: Windows Forms General Setting the value of a DataGridView Column

BexM

I must be completely missing something here then!


How do I got about doing the above The tutorial explains how to bind to the grid and add columns but it doesnt explain how to when you bind, runa function on the value you have just bound

I'm sorry if this seems like a silly question, but I think my mind set is in the wrong place and I need an example to get me going!





Re: Windows Forms General Setting the value of a DataGridView Column

Fábio

Did you notice the tutorial has four pages If you ran through the pages then I will try to explain something that they didn't cover there






Re: Windows Forms General Setting the value of a DataGridView Column

BexM

Hello Fabio!

Thanks for your patience with me. Yes I did read all 4 pages...

Let me explain exactly what I am trying to do.

The user needs to be able to go into the application and first choose the order of the column on the gridview, this means I need to be able to write something like:


datagridview.columns[0].fieldName= blah

datagridview.columns[1].fieldname= blah 2 etc...

Then databind, and all rows and columns will be populated.

The other part of the binding of the grid needs to involve the following,

Say column[1] has the fieldname status, I need to run a translation function on each status that comes from the database.

eg datagridview.columns[1].(valuewhen binding) = Translate(fieldvalue);

Maybe I need an onbind event for the particular column field But don't know how to set this.

Do you understand what I mean or am I still missing something and was this explained in the tutorial

Thanks

Bex





Re: Windows Forms General Setting the value of a DataGridView Column

Fábio

Well, first, the column names comes together with the datasource, you don't set the columns, if you want the columns to display in a different order you have to work with the datasource, like editing the SELECT statement and use it to display the order you want (i.e: instead of "SELECT Table.Status, Table.Name" use "SELECT Table.Name, Table.Status"). Second, if you want to format the value before it gets to the datagridview, you use the the CellFormatting event:

Code Block

private void dgvLoteTubo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

{

if (e.ColumnIndex == 1)

e.Value = Translate(e.Value);

}

Hope this is what you need,

Regards,

Fabio