-2

C#で作成した列の幅を広げようとしています私のコードは、

DataTable dt = new DataTable("MyTable");
dt.Columns.Add(new DataColumn("Project ID", typeof(int)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("name", typeof(double)));
dt.Columns.Add(new DataColumn("email", typeof(double)));
dt.Columns.Add(new DataColumn("description", typeof(double)));
dt.Columns.Add(new DataColumn("ownerdetail", typeof(double)));
DataRow dr;

幅を設定するには?私はそれを次のように実装することがわかりました、

dt.Columns.Add(new DataColumn("Title", typeof(string))).width; 

しかし、「.with」が存在しない場合、どうすれば解決できますか? ご提案をお待ちしております。

EDITED: グリッドビューに列が存在するように設定する方法私のコードは、

GridViewHcost.DataSource = dset;

私はネットからの助けとしてそれを試します、

GridViewHcost.Columns.width = 20;

しかし、このコマンドには " .Width " は存在しません。あなたの提案を願っています

4

7 に答える 7

3

ADataTableは、.Net フレームワークの非 UI クラスです。これは、変更する「幅」がないことを意味します。

答えは、あなたにはできないということです。

が UI コントロールにバインドされている場合DataTableは、代わりにそのコントロールの変更を検討する必要があります。

于 2013-06-07T09:54:29.633 に答える
2

私は同じ問題を抱えていました.dataTableをGridViewに追加した後、次のように必要なすべての列幅を変更できます:

GridView1.Rows[0].Cells[3].Width = 120;
于 2016-10-24T16:57:02.947 に答える
0

A DataColumn has no width, do you mean restrict the number of characters in the column via a constraint or affect the display in some way?

If you mean the display, then it depends on how you are outputting the data I.E. If you are you data binding to a GridView, you can override the RowDataBound event and customise the output.

If you mean constrain the field size, then I don't think there is anything built in you can use. I tend to validate the input field length manually before inserting into a database.

于 2013-06-07T09:59:03.703 に答える
0

DataTableオブジェクトに幅がありません。DataGridまたはで幅を設定できますGridViewDataTable行と列のコレクションです。それだけです。

と の両方DataGridにプロパティGridViewが必要です。Columns列の数がわかっていて、どの列の幅を拡張するかが正確にわかっている場合は、次を使用できます。

var column = GridView.Columns[columnIndex];
column.Width = 150;

それはそれについてです。

于 2013-06-07T09:54:39.103 に答える
0

データテーブルは、データのメモリ内ストレージに使用されます...そのデータは通常、データビューなどのGUIコントロールにバインドされ、データビューの列を広げることができます。

データビュー.幅

于 2013-06-07T09:54:58.393 に答える