Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Yesterday I was given a very good answer by TnTinMn about adding data from a tab delimited text file to the form elements on my UserControl.
<UserControl x:Class="Docker"
             d:DesignHeight="500" d:DesignWidth="250">
        <DataTemplate x:Key="cboNames">
            <TextBlock Text="{Binding Path=Name}" />
        <ComboBox IsEditable="True" Name="ComboBox1" Margin="10,0" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" ItemTemplate="{StaticResource cboNames}" />
        <TextBox Name="TextBox1" Margin="10,0" Text="{Binding Path=Address1}"/>
        <TextBox Name="TextBox2" Margin="10,0" Text="{Binding Path=Address2}"/>
        <TextBox Name="TextBox3" Margin="10,0" Text="{Binding Path=Phone}"/>
        <TextBox Name="TextBox4" Margin="10,0" Text="{Binding Path=Fax}"/>
        <TextBox Name="TextBox5" Margin="10,0" Text="{Binding Path=Cell}"/>
        <TextBox Name="TextBox6" Margin="10,0" Text="{Binding Path=Other}"/>
        <TextBox Name="TextBox7" Margin="10,0" Text="{Binding Path=Attn}"/>
        <TextBox Name="TextBox8" Margin="10,0" Text="{Binding Path=Email}"/>
Imports c = Corel.Interop.CorelDRAW
Imports v = Corel.Interop.VGCore
Imports System.IO

Partial Public Class Docker
    Dim WithEvents appDRAW As c.Application
    Private Dt As New System.Data.DataTable
    Private source As New Binding
    Public Sub New(app As Object)
        appDRAW = CType(app, c.Application)
    End Sub
    Private Sub Docker_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim r As System.Data.DataRow
        With Dt
            .Columns.Add("Name", GetType(String))
            .Columns.Add("Address1", GetType(String))
            .Columns.Add("Address2", GetType(String))
            .Columns.Add("Phone", GetType(String))
            .Columns.Add("Fax", GetType(String))
            .Columns.Add("Cell", GetType(String))
            .Columns.Add("Other", GetType(String))
            .Columns.Add("Attn", GetType(String))
            .Columns.Add("Email", GetType(String))
            Dim sr As New IO.StreamReader("C:\Users\sean\Dropbox\Visual Studio 2012\Projects\CustDB.txt")
            Do While sr.Peek() <> -1
                r = .NewRow
                r.ItemArray = sr.ReadLine().Split(New Char() {vbTab(0)}, 9, System.StringSplitOptions.None)
        End With
        DataContext = Dt
    End Sub
End Class
My biggest draw back now is that the combo box that receives the Name field only works if the control is set to IsEditable="False". If the control is set to IsEditable="True", then the top of the combo box only shows "System.Data.DataRowView". The drop down list has all of the customer names as expected, but does not change it's selected view when a list item is clicked. I need the control to be editable, so that I can type the name of the customer and have it find it in the list.
Also, this is a docker plugin for CorelDraw and I already have the code set up to watch for document changes. When a document is opened that already has a customer name embedded in the documents properties, the customer name combo box is populated with the embedded info. As it stands the other info does not update as expected when the combo box is changed via any method other than direct click selection. I'm hoping that both of these problems can be addressed with one fix.
1. How do I make the combo box editable and have it find the list item that matches the typed input?
2. How do I get the text box items to update when the combo box is changed via embedded document properties?
Posted 28-Feb-13 8:47am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755

Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100