DataGridView issue


M

Marco Pais

Hi there.

I have a DataGridView on a desktop application and it's being filled through
the use of a Web Service, wich returns a DataSet. The I use
datagrid.DataSource=mydataset.tables[0] to bind the data.
This dataset contains a table with 4 columns: id, description, status,
private. Column status can take 4 values, and private, 2 values.

My question is: how can I make the column status a
DataGridViewComboBoxColumn and column private a DataGridViewCheckBoxColumn?

I know that, at design time, I can add ComboBox and CheckBox columns, but
how can I mapp those columns with the data returned by the DataSet, trough
the web Service?

Thanks in advance.

Regards.

Marco
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

Marco,

Can you create a typed instance of the data set in your code which is
the same as what the server returns (when you created the reference for your
proxy, it should have created some sort of type which exposes these
properties properly).

Using that, you should be able to bind to ^that^ and then configure your
grid properly.
 
M

Marco Pais

Hi there.

I worked around using something like this:

ds = srv.GetData(); // the Web Method of my Web Service

dgv.AutoGenerateColumns = false;
dgv.DataSource = ds.Tables[0];

DataGridViewTextBoxColumn TextBoxColumn1 = new
DataGridViewTextBoxColumn();
TextBoxColumn1.HeaderText = "Id";
TextBoxColumn1.Width = 60;
TextBoxColumn1.DataPropertyName = "id";

DataGridViewCheckBoxColumn CheckBoxColumn = new
DataGridViewCheckBoxColumn();
CheckBoxColumn.HeaderText = "Descrição";
CheckBoxColumn.DataPropertyName = "estado";

dgv.Columns.Add(TextBoxColumn1);
dgv.Columns.Add(CheckBoxColumn);

It works!

Now, I'm having another problem. How can I uptade data via WS again?

If I used DataAdapter/DataSet, I would be easier. But, in this case, I will
use a Web Service to update data on database - something like, when I click
an update button, it will execute:

srv.UpdateData(data); // srv - my Web Service

How can I get the data that I edited in DataGridView and update database via
WS?

Thanks again.

Ragards.


Nicholas Paldino said:
Marco,

Can you create a typed instance of the data set in your code which is
the same as what the server returns (when you created the reference for
your proxy, it should have created some sort of type which exposes these
properties properly).

Using that, you should be able to bind to ^that^ and then configure
your grid properly.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Marco Pais said:
Hi there.

I have a DataGridView on a desktop application and it's being filled
through the use of a Web Service, wich returns a DataSet. The I use
datagrid.DataSource=mydataset.tables[0] to bind the data.
This dataset contains a table with 4 columns: id, description, status,
private. Column status can take 4 values, and private, 2 values.

My question is: how can I make the column status a
DataGridViewComboBoxColumn and column private a
DataGridViewCheckBoxColumn?

I know that, at design time, I can add ComboBox and CheckBox columns, but
how can I mapp those columns with the data returned by the DataSet,
trough the web Service?

Thanks in advance.

Regards.

Marco
 
Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

Marco,

Well, since you attach the table as the DataSource for the grid, you can
get the DataTable back from the DataSource and then access the DataSet
through the DataSet property on the DataTable. Then you can pass that back
to the service.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Marco Pais said:
Hi there.

I worked around using something like this:

ds = srv.GetData(); // the Web Method of my Web Service

dgv.AutoGenerateColumns = false;
dgv.DataSource = ds.Tables[0];

DataGridViewTextBoxColumn TextBoxColumn1 = new
DataGridViewTextBoxColumn();
TextBoxColumn1.HeaderText = "Id";
TextBoxColumn1.Width = 60;
TextBoxColumn1.DataPropertyName = "id";

DataGridViewCheckBoxColumn CheckBoxColumn = new
DataGridViewCheckBoxColumn();
CheckBoxColumn.HeaderText = "Descrição";
CheckBoxColumn.DataPropertyName = "estado";

dgv.Columns.Add(TextBoxColumn1);
dgv.Columns.Add(CheckBoxColumn);

It works!

Now, I'm having another problem. How can I uptade data via WS again?

If I used DataAdapter/DataSet, I would be easier. But, in this case, I
will use a Web Service to update data on database - something like, when I
click an update button, it will execute:

srv.UpdateData(data); // srv - my Web Service

How can I get the data that I edited in DataGridView and update database
via WS?

Thanks again.

Ragards.


Nicholas Paldino said:
Marco,

Can you create a typed instance of the data set in your code which is
the same as what the server returns (when you created the reference for
your proxy, it should have created some sort of type which exposes these
properties properly).

Using that, you should be able to bind to ^that^ and then configure
your grid properly.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Marco Pais said:
Hi there.

I have a DataGridView on a desktop application and it's being filled
through the use of a Web Service, wich returns a DataSet. The I use
datagrid.DataSource=mydataset.tables[0] to bind the data.
This dataset contains a table with 4 columns: id, description, status,
private. Column status can take 4 values, and private, 2 values.

My question is: how can I make the column status a
DataGridViewComboBoxColumn and column private a
DataGridViewCheckBoxColumn?

I know that, at design time, I can add ComboBox and CheckBox columns,
but how can I mapp those columns with the data returned by the DataSet,
trough the web Service?

Thanks in advance.

Regards.

Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top