博文

MSFlexGrid的应用(2005-07-22 14:17:00)

摘要:MSFLEXGRID控件里,想在单元格里输入数据,而且要求是:在第二行第一列的位置开始,能够输入数据,输入之后还要求判断回车键有没有按下,如果按下了,就表明这个内容填写了,根据填写的内容然后同一行里其他单元格里填充内容,最后一行填完整了,再换到第二行。麻烦各位了。 -------------------------------------------------------------------------------- 一段利用MsFlexGrid控件作的非常简单的程序,可以输入英文字符和数字,按回车自动右移,支持方向键,可以自动添加行。只用到一个MsFlexGrid控件,没有别的: Private Sub Form_Load() Grid1.Rows = 10 Grid1.Cols = 6 End Sub Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer) Dim X As Long Dim Y As Long Dim L As Long Dim Tmp As String X = Grid1.Col Y = Grid1.Row Select Case KeyCode    Case 13       X = X + 1       If X >= Grid1.Cols Then          X = 1          Y = Y + 1          If Y >= Grid1.Rows Then Grid1.Rows = Grid1.Rows + 1       End If       Grid1.Col = X &nb......

阅读全文(4279) | 评论:0

将MsFlexGrid控件中显示的内容输出到Excel表格中进行 (2005-07-22 14:09:00)

摘要: Public Sub OutDataToExcel(Flex As MSFlexGrid) '导出至Excel  Dim s As String  Dim i As Integer  Dim j As Integer  Dim k As Integer  On Error GoTo Ert  Me.MousePointer = 11  Dim Excelapp As Excel.Application  Set Excelapp = New Excel.Application  On Error Resume Next  DoEvents  Excelapp.SheetsInNewWorkbook = 1  Excelapp.Workbooks.Add  Excelapp.ActiveSheet.Cells(1, 3) = s  Excelapp.Range("C1").Select  Excelapp.Selection.Font.FontStyle = "Bold"  Excelapp.Selection.Font.Size = 16  With Flex  k = .Rows  For i = 0 To k - 1  For j = 0 To .Cols - 1  DoEvents  Excelapp.ActiveSheet.Cells(3 + i, j + 1) = "'" & .TextMatrix(i, j)  Next j  Next i  End With  Me.MousePointer = 0  Excelapp.Visible = True  Excelapp.Sheets.PrintPreview Ert:  If Not (Excelapp Is Nothing) Then  Excelapp.Quit  End If End Sub ......

阅读全文(4272) | 评论:0

MSFlexGrid的使用(2005-07-22 13:26:00)

摘要:Private Sub SetGridTitle()    With flexGrid       .FormatString = "流水号|录入时间|赔案号|保单号|被保险人|厂牌型号|保险类型|牌照号码|使用性质|业务部门|业务员|理赔员|立案日期|合计"              .ColAlignment(0) = flexAlignLeftCenter       .ColAlignment(1) = flexAlignLeftCenter       .ColAlignment(2) = flexAlignLeftCenter       .ColAlignment(3) = flexAlignLeftCenter       .ColAlignment(4) = flexAlignLeftCenter       .ColAlignment(5) = flexAlignLeftCenter       .ColAlignment(6) = flexAlignLeftCenter       .ColAlignment(7) = flexAlignLeftCenter       .ColAlignment(8) = flexAlignLeftCenter       .ColAlignment(9) = flexAlignLeftCenter     &nb......

阅读全文(3911) | 评论:0

如何用MsflexGrid网格显示查询数据?(2005-07-22 13:20:00)

摘要:BOOL CLOGINFO::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_mf.SetRows(2); m_mf.SetCols(4); m_mf.SetColWidth(0,800); m_mf.SetColWidth(1,1200); m_mf.SetColWidth(2,1000); m_mf.SetColWidth(3,6000); m_mf.SetTextMatrix(0,1,"日期"); m_mf.SetTextMatrix(0,2,"时间"); m_mf.SetTextMatrix(0,3,"事件"); CString strSql,row; strSql.Insert(0,"select 日期,时间,事件 from slog order by 日期 desc,时间 desc"); _RecordsetPtr pRs; CKaoqinApp* ap=(CKaoqinApp*)AfxGetApp(); ::CoInitialize(NULL); pRs.CreateInstance(__uuidof(Recordset)); pRs->Open(_bstr_t(strSql),ap->m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText); if(0<pRs->RecordCount) { m_mf.SetRows(pRs->RecordCount+1); } BeginWaitCursor(); try { for(long i=1;i<pRs->RecordCount;i++) { row.Empty(); row.Format("%d",i); m_mf.SetTextMatrix(i,0,row); for(long j=1;j<4;j++) { m_mf.SetTextMatrix(i,j,(char*)_bstr_t(pRs->GetFields()->GetItem(j-1L)......

阅读全文(4676) | 评论:0

MSFLEXGrid源码  (2005-07-22 13:15:00)

摘要:Option Explicit Dim DefColor Dim Horizenw Private Sub Form_Load() &#39;========================== Dim I As Integer, lRow As Long With MSFlexGrid1 &#39;初始化表格 .Cols = 9 .Rows = 8 For I = 1 To 4 .ColWidth(I) = 750 Next I For I = 5 To 8 .ColWidth(I) = 950 Next I lRow = 1 For I = 1 To 7 .TextMatrix(lRow, 4) = 1 .TextMatrix(lRow, 0) = 表达式 & I lRow = 1 lRow .RowHeight(I) = 400 Next I End With End Sub Private Sub MSFlexGrid1_DblClick() Dim I With MSFlexGrid1 If .MouseCol = 0 Or .MouseRow = 0 Then Exit Sub Text1.Left = .Left .CellLeft: Text1.Top = .Top .CellTop Text1.Height = .CellHeight: Text1.Width = .CellWidth Text1.Text = .Clip Text1.Visible = True: Text1.SetFocus Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text) End With End Sub Private Sub MSFlexGrid1_KeyUp(KeyCode As Integer, shift As Integer) If KeyCode = vbKeyDelete Then MSFlexGrid1.Clip = End Sub Private Sub MSFlexGrid1_LeaveCell() MSFlexGrid1.CellBackColor = DefColor End Sub Private Sub MSFlexGrid1_RowColChange() Wi......

阅读全文(3947) | 评论:0

MSFlexGrid控件可编辑的简单实现方法2(2005-07-22 13:14:00)

摘要:'实现步骤 '1 打开 VB5, 开启一个新的工程。 '2 在菜单"工程" 中选择 "部件", 在列表中选中 '"Microsoft FlexGrid Control .." '3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 '修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 '为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, 'BorderStyle 为 None(0)。 '4 在Form1 的代码中增加声明: Const ASC_ENTER = 13 '回车 Dim gRow As Integer Dim gCol As Integer '5 增加代码到 Grid_KeyPress 过程: Private Sub Grid1_KeyPress(KeyAscii As Integer) ' Move the text box to the current grid cell: Text1.Top = Grid1.CellTop + Grid1.Top Text1.Left = Grid1.CellLeft + Grid1.Left ' Save the position of the grids Row and Col for later: gRow = Grid1.Row gCol = Grid1.Col ' Make text box same size as current grid cell: Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY ' Transfer the grid cell text: Text1.Text = Grid1.Text ' Show the text box: Text1.Visible = True Text1.ZOrder 0 ' 把 Text1 放到最前面! Text1.SetFocus ' Redirect this KeyPress event to t......

阅读全文(5462) | 评论:0

MSFlexGrid控件可编辑的简单实现方法(2005-07-22 13:13:00)

摘要: 在窗体上放一MSFlexGrid和Text控件各一个。 代码如下: Private Sub Form_Load()     Text1.Move -10000, -10000, 1, 1     Text1.Text = ""     MSFlexGrid1.Cols = 6  '6列 可根据自己需要调整。     MSFlexGrid1.Rows = 6 '6行 End Sub Private Sub MSFlexGrid1_EnterCell()     MSFlexGrid1.CellBackColor = vbBlue     MSFlexGrid1.CellForeColor = vbWhite     Text1.Text = MSFlexGrid1.Text     Text1.SelStart = 0     Text1.SelLength = Len(Text1.Text) End Sub Private Sub MSFlexGrid1_LeaveCell()     MSFlexGrid1.CellBackColor = vbWhite     MSFlexGrid1.CellForeColor = vbBlue End Sub Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)     Text1.SetFocus End Sub Private Sub Text1_Change()     MSFlexGrid1.Text = Text1.T......

阅读全文(3247) | 评论:0

加强型的msflexgrid3(2005-07-22 13:10:00)

摘要:'以下程式处理Multi-column Selection的问题 Private Sub ProcMultiColSel(ByVal Shift As Integer) Dim i As Long, HaveSel As Boolean Dim SelSt As Long, SelEnd As Long Dim OldRowSel As Long, OldColSel As Long With MSFlexGrid1 OldRowSel = .RowSel: OldColSel = .ColSel If HaveSelEntireCol Then    '如果有整行被选取的清况,则计算选取的起始结束行    SelSt = IIf(.Col <= .ColSel, .Col, .ColSel)    SelEnd = IIf(.Col > .ColSel, .Col, .ColSel)    For i = SelSt To SelEnd        ColSelect(i) = True    Next    .CellBackColor = .BackColorSel    If Shift <> vbCtrlMask Then '没有按Ctl键则清除其他Column的Selection       Call RefreshCols(SelSt, SelEnd)    End If Else    HaveSel = False    For i = 1 To .Cols - 1        HaveSel = HaveSel Or ColSelect(i)    Next    If......

阅读全文(3093) | 评论:0

加强型的msflexgrid2(2005-07-22 13:09:00)

摘要:'以下在Form需一个MSFlexGrid, 一个TextBox Option Explicit Private OldText As String Private ColSelect() As Boolean Private SaveCellBkColor As Long Private Sub Form_Load() Text1.Visible = False Me.Show With MSFlexGrid1      .Cols = 5      .Rows = 15      ReDim ColSelect(1 To .Cols - 1)      SaveCellBkColor = .CellBackColor      Call InitGrid      .AllowBigSelection = True      .FillStyle = flexFillRepeat      '.AllowUserResizing = True  '请事先设好 End With End Sub Private Sub InitGrid() Dim i As Long With MSFlexGrid1   .Row = 0   For i = 1 To .Cols - 1       .Col = i: .Text = "Col" + Format(i, "00") '若Cols超出99,则修改Format   Next               ......

阅读全文(3377) | 评论:0

加强型的 MSFlexGrid&nbsp;1(2005-07-22 13:08:00)

摘要:加强型的 MSFlexGrid 来源:cww 更改王国荣的范例 修改过王国荣先生的范後,功能如下: 1.在MSFlexGrid上按Enter时,可以编修当格(Current Cell)的内容 2.在MSFlexGrid上Click时,可以编修当格(Current Cell)的内容 3.在MSFlexGrid上固定列与固定行上面按Mouse右键时可以修改其Title 4.允许MultiLine/MultiCol的Selection 与按Ctl-Mouse左键的MultiSelect Columns 5.进入Cell的EditMode时,按up/Down键会离开Current Cell而进入上/下 一行的Cell 6.进入Cell的EditMode时,按Escape回覆原本的字串 MSFlexGrid内的资料原本是不能让使用者直接KeyIn的,所以找个变通的方式,便是使用 TextBox来Keyin,再把TextBox内的值放入MSFlexGrid中,但重点就变成TextBox如何设 定位置、大小於MSFlexGrid之上。这个部份在toEditGrid的程式中做。何时启动TextBox 让之可以输入资料呢,有两个地方,一个在MSFlexGrid上的Mouse_Click,而且考虑可以 在Grid上做多栏的选取,所以只有在.ColSel = .Col And .RowSel = .Row时才可以进入 EditMode。另一个地方在MSFlexGrid上按Enter,也会令之进入EditMode。而离开EditMode 的时机在於TextBox上按Enter/Up/Down/Esc 键。 另外,我们如果想要保留MSFlexGrid可以整列整行选取,而且又可以更动MSFlexGrid最 上与最左边的固定列之Title,我的做法是,在MSFlexGrid上MouseUp时来判定Mouse所在 的Col与Row,如果MouseCol=0 or MouseRow = 0代表是在FixedCol/FixedRow 上按下 Mouse,如果按的是右键表示要修改FixCol或FixRow的Title,如果是左键,那不做任何 处理,此时,如果AllowBigSelection=True时,则会选取整行或整列。' ......

阅读全文(2992) | 评论:0