PDA

View Full Version : MSFLEXGRID



شفیعی
چهارشنبه 14 خرداد 1382, 20:13 عصر
سلام
من یک MSFLEXGRID روی فرم قرار داده ام وبرنامه را اجرا می کنم پس از اجرا در داخل این جدول نمی توان از طریق صفحه کلید اطلاعات وارد کنم لطفا بنده را راهنمائی نمائید

مسعود م
شنبه 17 خرداد 1382, 11:19 صبح
تا جایی که من می دانم با MSFlexGrid نمی توان اطلاعات وارد کرد و فقط می توان دید .

شفیعی
شنبه 17 خرداد 1382, 19:25 عصر
دوست عزیز متشکرم
حداقل یک جدول به بنده معرفی کن که بتوان درآن در هنگام اجرای برنامه اطلاعات وارد بکنم :twisted:

morteza_dehghan
یک شنبه 18 خرداد 1382, 04:27 صبح
سلام
دوست عزیز شما میتوانید از data grid استفاده کنید

همه گونه امکاناتی دارد

درج حذف و اصلاح :wink: چیز دیگه ای هم میخوای :lol:

شفیعی
یک شنبه 18 خرداد 1382, 19:51 عصر
دوست عزیز سلام
data grid را امتحان کردم مشکل این است که به data grid باید یک بانک اطلاعاتی را وصل نماید در صورتی که بنده می خواهم یک فایل متنی را خوانده در یک جدول نمایش داده به کاربر اجازه دهم اطلاعات را تغییر ویا حذف ویا اضافه نماید وسپس این جدول را در فایل متنی ذخیره نماییم نمی خواهم از بانکهای اطلااعاتی استفاده کنم لطفا بنده را راهنمائی نمائید :lol:

morteza_dehghan
چهارشنبه 21 خرداد 1382, 02:37 صبح
سلام
دوست عزیز اولا والا من فقط با بانکهای اطلاعاتی کار کردم و هرگز سراغ فایلهای اطلاعاتی نرفتم در نتیجه شرمنده هستم که نمیتوانم هیچ کمکی بکنم

دوما خوب بود که شما همان اول سوالتان را کامل بیان میکردید و می فرمودید که با فایل میخواهید کار کنید نه با بانک اطلاعاتی :x :x

شفیعی
چهارشنبه 21 خرداد 1382, 05:39 صبح
دوست عزیز
من می خواهم یک فایل TEXT را خوانده اطلاعاتش را درجدول نمایش دهم وبه کاربر اجازه دهم اطلاعات تغییر دهد وسپس جدول را دوباره در فایل متنی کپی نماییم :lol:

akram
شنبه 24 خرداد 1382, 15:17 عصر
سلام
برای وروى اءلاعات flexgrid باید خاصیت editable انرا true کنید

سعید قدیری مقدم
سه شنبه 27 خرداد 1382, 09:42 صبح
سلام . شما می خواهید یک فایل متنی به غیر از فایل بانک اطلاعاتی مخصوصا فایل های متنی را بکمک MSFlexGrid تغییر بد هید خوب این کار بکمک کد نویسی قابل انجام است
چون MSFlexGrid فقط وظیفه نمایش اطلاعات راندارد و اصولا MSFlexGrid بجای DataGrid برای فایلهای متنی طراحی شده است در زیر من روش تغییر اطلاعات را برای شما دوستان عزیز نوشته ام در صورتی که در بیان من مشکلی بود و با مشکل مواجه شدید می توانید بامن تماس بگیرید خوشحال می شوم با هم بیشتر آشنا شویم :)
ایجاد تغییرات در MSFlexGrid بسیار راحت است :wink: برای این کار شما باید همراه Form اصلی خودتون یک Form دیگه درست کنید و داخل او ن Form دوم یک TextBox قرار بدهید
حالا شما به یک مقدارد کد نویسی احتیاج دارید تا رابطه را بین TextBox و MSFlexGrid ایجاد کنید
در این کد نویسی قصد ما این خواهد بود که هر کدام از سلولهای MSFlexGrid را که انتخاب کردیم به کمک TextBox اطلاعات داخل سلول تعییر کند
ابتدا کدی احتیاج است که مکان سلول را تعید کند برای این منظور شما می توانید یک Module1 ایجاد کنید و در داخل آن 2 متغییر که مورد نیاز است را تعریف کنید

Public CelCol As String
Public CelRow As String

متغییر اولی مختصات ستون و متغییر دوم مختصات ردیف را در خود ذخیره می کند
حال برای اینکه به متغییر ها مختصات را بدهیم به کد زیر نیاز داریم

Private Sub MSFlexGrid1_Click()
Dim CelCol, CelRow
CelCol = MSFlexGrid1.Row
CelRow = MSFlexGrid1.Col
Form2.Show
Form2.Text1 = MSFlexGrid1.Text
End Sub


در این صورت هر کدام از سلول های داخل MSFlexGrid را کلیک کنیم مختصات ستون داخل متغییر ها وارد می شود و سپس Form دوم که ایجاد کرده ام نمایش داده می شود و اطلاعاتی که داخل سلول نوشته شده است به TextBox داخل Form دوم دیده می شود

حالا باید کدی را برای TextBox بنویسیم تا اطلاعات داخل آن در سلول مورد نظر نوشته شود برای این منظور از این کد استفاده می کنیم

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Form1.MSFlexGrid1.Col = CelCol
Form1.MSFlexGrid1.Row = CelRow
Form1.MSFlexGrid1.Text = Text1.Text
End If
End Sub

با استفاده از این کد متن داخل TextBox در سلول مورد نظر در MSFlexGrid نوشته می شود.

VBCitizen
پنج شنبه 29 خرداد 1382, 13:44 عصر
سلام دوست عزیز من قطعه برنامه ای برات ارسال میکنم که Flexgrid را Editableمیکنه با کمی تغییر می تونی خیلی کارا بکنی. اگه سئوالی داشتی بپرس.

این متن را از یک کتاب لاتین برات فرستادم اگه مایل بودی آدرس میل بده تا این فصل گتاب رو کامل برات ارسال کنم.

فقط کافیه یک textbox به اسم txtCellEditor داشته باشی و متن پائین رو Copy و Paste کنی.

Making the grid editable
While the Hierarchical FlexGrid control is inherently a read-only control, it doesn't take much effort to add some basic editing capabilities to it. The trick, as you might have guessed, is to superimpose a TextBox control over the current cell so that it appears as if it belongs to the grid. You need to trap a few events to keep the TextBox in sync with the grid, but on the whole it doesn't require much code.

To make this technique work, add a TextBox control to the form and then set its Visible property to False, its MultiLine property to True, and its BorderStyle property to 0-None. These routines cause the phantom TextBox (named txtCellEditor) to appear and disappear as needed:

' These variables keep track of the cell that was active
' when edit mode was entered.
Dim cellRow As Long, cellCol As Long

Sub ShowCellEditor()
With MSHFlexGrid1
' Cancel range selection, if any.
.RowSel = .Row
.ColSel = .Col
' Move the cell editor into place by making it one pixel smaller
' than the current cell.
txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
.CellWidth - ScaleX(1, vbPixels, vbTwips), _
.CellHeight - ScaleY(1, vbPixels, vbTwips)
' Transfer the contents of the current cell into the TextBox.
txtCellEditor.Text = .Text
' Move the TextBox in front of the grid.
txtCellEditor.Visible = True
txtCellEditor.ZOrder
txtCellEditor.SetFocus
' Remember current coordinates for later.
cellRow = .Row
cellCol = .Col
End With
End Sub

Sub HideCellEditor(Optional Cancel As Boolean)
' Hide the TextBox control if necessary.
If txtCellEditor.Visible Then
' If the operation hasn't been canceled, transfer the contents
' of the TextBox into the cell that was active.
If Not Cancel Then
MSHFlexGrid1.TextMatrix(cellRow, cellCol) = txtCellEditor.Text
End If
txtCellEditor.Visible = False
End If
End Sub




The ShowCellEditor routine can move the TextBox into place, thanks to the grid's CellLeft, CellTop, CellWidth, and CellHeight properties. The next step is to determine when cell editing is activated. In the demonstration program, this happens when the grid is double-clicked or when the user presses an alphanumeric key when the grid has the input focus:

Private Sub MSHFlexGrid1_DblClick()
ShowCellEditor
End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
ShowCellEditor
' If it's an alphanumeric key, it is passed to the TextBox.
If KeyAscii >= 32 Then
txtCellEditor.Text = Chr$(KeyAscii)
txtCellEditor.SelStart = 1
End If
End Sub




Edit mode is terminated when the TextBox loses the focus (for example, when the user clicks elsewhere in the grid), or when either the Enter or Esc key is pressed:

Private Sub txtCellEditor_LostFocus()
HideCellEditor
End Sub

Private Sub txtCellEditor_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 13
HideCellEditor
Case 27
HideCellEditor True ' Also cancel the edit.
End Select
End Sub




It should be noted that this simple example modifies only the contents of the Hierarchical FlexGrid control without affecting the underlying ADO hierarchical Recordset. Updating the underlying ADO hierarchical Recordset is a more complex task, but the grid offers all the properties you need to determine which field in which record should be modified

شفیعی
پنج شنبه 29 خرداد 1382, 19:33 عصر
دوست عزیز سلام
از اینکه سوال بنده را جواب دادید متشکرم
NASER_SHAFIEI@YAHOO.COM