AvivG

Hello Friends,

I need your help setting up a DataGrid. I have this DataGrid, and I want the following
options to be available on it, some I got working, and some only work if I disable another option. How can I get all of these options to be available on my DataGrid

1) I want to be able to select a single line, or multiple lines. This by clicking on one cell in the
row. I want it to become blue, like when selecting text. If I click control or shift, it will select multiple rows.
This in order to remove rows from the grid.

2) I want to be able to sort the list by a specific coloumn in it.

3) I want the height of the row to be determined by the amount of text inside it. thus if the text in a specific cell in a row takes a bigger space than the default row height, that row's height will be enlarged.
Imagine this situation on a Word's table; if you enter
a big amount of text in a cell, that entire row's height enlarges.

4) Something I don't want - when you click on a cell, the text inside it becomes blue (only in that specific cell) and its format is changed.
e.g if I have:
"This is a
Nice line"
if I click on it it becomes blue and the text becomes "This is aNice line"
I never want the text's format to change.

The problems I have: if I "enable=false" the DataGrid, I get no event for a click on it
thus I can't select it (i.e turn it blue).

I'm very sorry for this over-sized message and I would really appreciate your help.

Thank you very much,
Aviv Giladi



Re: Windows Forms Data Controls and Databinding DataGrid help

Zamial

It's important to know which version of .net you are no as the grid has gone through some changes




Re: Windows Forms Data Controls and Databinding DataGrid help

AvivG

Hey Zamial,

Thanks for the reply. This project is an old project that i'm woriking on and it's in Visual Studio 2003 .Net

Maybe if I can import a DataGrid that would solve some problems How can I do that

Thanks,

Aviv





Re: Windows Forms Data Controls and Databinding DataGrid help

Zamial

I'm not sure actually i've never really used the datagrid in 1.1 to any great advantage other than displaying data really. I didn't like the grid that much but it is certainly improved in .net 2 as the GridView and that control I have used much more successfully.




Re: Windows Forms Data Controls and Databinding DataGrid help

Zhi-Xin Ye - MSFT

A DataGridView(.NET 2.0 contorl) can do all you need as you described above, using a DataGrid control to do these stuff would cause you a headache.






Re: Windows Forms Data Controls and Databinding DataGrid help

Zhi-Xin Ye - MSFT

Anyway, for a .NET1.x control DataGrid, the solution would be:

1). I want to be able to select a single line, or multiple lines.

This feature is supported by default, you can click on the row header to select a single row, and click on the row headers while pressing Shift or Ctrl key to select multiple rows.

2). I want to be able to sort the list by a specific coloumn in it.

This feature is also be supported by default. Just click on the column header to sort it.

3). I want the height of the row to be determined by the amount of text inside it.

To enable the word wrap feature in the cell, you have to use a GridColumnStyles, set Multiline and WordWrap property for the TextBox inside, something like this:

DataGridTextBoxColumn tbc = new DataGridTextBoxColumn();
tbc.MappingName = "c1";
tbc.HeaderText = "c1";
tbc.TextBox.Multiline = true;
tbc.TextBox.WordWrap = true;

DataGridTableStyle style = new DataGridTableStyle();
style.GridColumnStyles.Add(tbc);
this.dataGrid1.TableStyles.Add(style);


However, these settings enable the word wrap, but do not adjust the row height automatically, you have to set the height manually based on the content, there's a solution about how to change the DataGrid row height pragrammatically at this site;

4). For this issue, set Mulitline and WordWrap properties as in #3). would be fix it.

5). Set Enable property to false would certainly make the DataGrid disabled, I think what you want is the ReadOnly property instead.