nafiseh_hch
Member
دوباره سلام ![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
توی فرم من یه دیتاگرید هست که بصورت زیر پرش کردم
وقتی اجرا میکنم درست اجرا میشه ولی وقتی فرم رو می بندم دوباره باز می کنم میاد روی خط آخر این پیغام رو میده
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
من چجوری میتونم برای ستون های دیتاگریدم اندازه تعیین کنم؟؟
وی اینکه چجوری header ها رو غیر قابل کلیک کنم برای sort
چون اونم error میده
توی فرم من یه دیتاگرید هست که بصورت زیر پرش کردم
کد:
[SIZE=2]
cmd = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SqlCommand([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"SELECT Id, FdoOffice, CoName, comptxt2 FROM Comission01 where comptxt2 is not null"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], MySqlConnection)
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MySqlConnection.State = ConnectionState.Closed [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MySqlConnection.Open()
myDA = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SqlDataAdapter(cmd)
myDataSet = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DataSet()
myDA.Fill(myDataSet, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" Comission01"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
dv = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DataView(myDataSet.Tables([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" Comission01"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]))
dg1.DataSource = dv
dv.Sort = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"FdoOffice DESC"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"FdoOffice"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).HeaderText = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"comptxt2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).HeaderText = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" "
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"CoName"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).HeaderText = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" "
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Id"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).Visible = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"comptxt2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"CoName"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]dg1.Columns([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"FdoOffice"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]dg1.Columns.Item(0).Width = 40
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000][/COLOR][/SIZE][/COLOR][/SIZE]
وقتی اجرا میکنم درست اجرا میشه ولی وقتی فرم رو می بندم دوباره باز می کنم میاد روی خط آخر این پیغام رو میده
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
من چجوری میتونم برای ستون های دیتاگریدم اندازه تعیین کنم؟؟
وی اینکه چجوری header ها رو غیر قابل کلیک کنم برای sort
چون اونم error میده