Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / VBA + XML выборка данных / 9 сообщений из 9, страница 1 из 1
28.08.2013, 12:45
    #38379749
Saules
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
Добрый день, уважаемые форумчане
подскажите как правильно сделать выборку данных для двух comboBox из
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
  <Domains>
      <DomainListDef name="Test" numColumns="3" genFile="Test.xml">
        <domainRow col1="1 line" col2="7311050100" col3="101"/>
        <domainRow col1="1.1 line" col2="7311050600" col3="101"/>
        <domainRow col1="1.2 line" col2="7311050700" col3="101"/>
        <domainRow col1="2 line" col2="7311050200" col3="102"/>
        <domainRow col1="3 line" col2="7311050300" col3="103"/>
        <domainRow col1="Main 1 line" col3="101" />
	<domainRow col1="Main 2 line" col3="102" />
  	<domainRow col1="Main 3 line" col3="103" />
      </DomainListDef>
    </Domains>

xml
в основном comboBoxe должна быть информация:
"Main 1 line"
"Main 2 line"
"Main 3 line"
при выборе из него, например, строки "Main 1 line" во втором комбике должны появится
"1 line"
"1.1 line"
"1.2 line"

мой код для первого комбика:
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim doc As XDocument = XDocument.Load("Test.xml")
        Dim Result = doc.Root.Descendants("Domains").Elements("DomainListDef").Elements("domainRow").Where(Function(p)
                                                                                                               Return p.Attribute("col3").Value = "105"
                                                                                                           End Function)
        For Each ele In Result
            MsgBox(ele.Attribute("col1").Value)
            mainBox.Items.Add(ele.Attribute("col1").Value)
        Next


    End Sub


не понимаю как правильно написать выборку только тех строк, у которых нет аттрибута "col2"
спасибо за советы!
...
Рейтинг: 0 / 0
28.08.2013, 13:04
    #38379782
Shocker.Pro
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
А где тут VBA?
...
Рейтинг: 0 / 0
28.08.2013, 15:00
    #38379942
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
это VB.NET

Модератор: Тема перенесена из форума "Visual Basic".
...
Рейтинг: 0 / 0
02.09.2013, 17:35
    #38384472
Saules
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
помогите разобратся с ошибками, уже все мозги сломал, но понять где кроется проблема не могу
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        mainBox.DataSource = GetMainItems()
        mainBox.DisplayMember = "Name"
        mainBox.ValueMember = "ID"  '' в immediate window : A first chance exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll  но дальше идет

    End Sub

  
    Function GetMainItems() As List(Of MainItems)

        Dim MainItems = New List(Of MainItems)

        Dim doc As XDocument = XDocument.Load("test.xml")
        Dim Result = doc.Root.Descendants("Domains").Elements("DomainListDef").Elements("domainRow").Where(Function(p)
                                                                                                               Return IsNothing(p.Attribute("col2"))
                                                                                                           End Function)
        For Each ele In Result
            If Not IsNothing(ele.Attribute("col1")) And Not IsNothing(ele.Attribute("col3")) Then
                Debug.Print(ele.Attribute("col1").Value)
''Main 1 line
''Main 2 line
''Main 3 line

                mainBox.Items.Add(New MainItems(ele.Attribute("col1").Value, ele.Attribute("col3").Value))
            End If
        Next

        Return MainItems

    End Function


    Private Sub mainBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mainBox.SelectedIndexChanged

          Try
            subBox.DataSource = GetSubItems()
            subBox.DisplayMember = "Name"
            subBox.ValueMember = "ID"
''а вот тут пишет в immediate window :A first chance exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll и при смене значений в mainBox не меняет значения в subBox
''без Try-Catch вылетает ArgumentException  was unhandled (System.ArgumentException was unhandled  HResult=-2147024809
''Message=Cannot bind to the new value member. Parameter name: value  ParamName=value)


        Catch argEx As ArgumentException

            MsgBox("ALARM")
        End Try
      


    End Sub
    Function GetSubItems() As List(Of SubItems)

        Dim SubItems = New List(Of SubItems)
        Dim oItem As MainItems = CType(mainBox.SelectedItem, MainItems)
        Dim doc As XDocument = XDocument.Load("test.xml")
        subBox.SelectedIndex = -1
        subBox.Items.Clear()
        subBox.Text = "Select..."

        Dim Result = doc.Root.Descendants("Domains").Elements("DomainListDef").Elements("domainRow").Where(Function(p)
                                                                                                               Return Not IsNothing(p.Attribute("col3")) And Not IsNothing(p.Attribute("col2"))
                                                                                                           End Function)
        Debug.Print(oItem.Value) ''103

        For Each ele In Result
            If ele.Attribute("col3").Value.Equals(oItem.Value) Then
                Debug.Print(ele.Attribute("col1").Value) ''3 line
                subBox.Items.Add(New SubItems(ele.Attribute("col1").Value, ele.Attribute("col2").Value))
            End If
        Next

        Return SubItems

    End Function


    Public Class MainItems

        Private mText As String
        Private mValue As String

        Public Sub New(ByVal pText As String, ByVal pValue As String)
            mText = pText
            mValue = pValue
        End Sub

        Public ReadOnly Property Text() As String
            Get
                Return mText
            End Get
        End Property

        Public ReadOnly Property Value() As String
            Get
                Return mValue
            End Get
        End Property

        Public Overrides Function ToString() As String
            Return mText
        End Function

    End Class

    Public Class SubItems

        Private sText As String
        Private sValue As String

        Public Sub New(ByVal pText As String, ByVal pValue As String)
            sText = pText
            sValue = pValue
        End Sub

        Public ReadOnly Property Text() As String
            Get
                Return sText
            End Get
        End Property

        Public ReadOnly Property Value() As String
            Get
                Return sValue
            End Get
        End Property

        Public Overrides Function ToString() As String
            Return sText
        End Function

    End Class

End Class
...
Рейтинг: 0 / 0
02.09.2013, 17:51
    #38384496
buser
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
Вы хоть уточните... в чем беда-то?

Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
void Main()
{
	XElement doc = XElement.Parse(@"<Domains>
	      <DomainListDef name=""Test"" numColumns=""3"" genFile=""Test.xml"">
	        <domainRow col1=""1 line"" col2=""7311050100"" col3=""101""/>
	        <domainRow col1=""1.1 line"" col2=""7311050600"" col3=""101""/>
	        <domainRow col1=""1.2 line"" col2=""7311050700"" col3=""101""/>
	        <domainRow col1=""2 line"" col2=""7311050200"" col3=""102""/>
	        <domainRow col1=""3 line"" col2=""7311050300"" col3=""103""/>
	        <domainRow col1=""Main 1 line"" col3=""101"" />
			<domainRow col1=""Main 2 line"" col3=""102"" />
	  		<domainRow col1=""Main 3 line"" col3=""103"" />
	      </DomainListDef>
	   </Domains>");
	   
	  var first_list = doc
	  					.XPathSelectElements(".//domainRow[not(@col2)]")
						.Select(x => new { 
											col1 = x.Attribute("col1").Value,
											col3 = x.Attribute("col3").Value
										 }  
							    ) ;
	  
	  var second_list = doc
	  					.XPathSelectElements(".//domainRow[(@col2)]")
						.Select(x => new { 
											col1 = x.Attribute("col1").Value,
											col2 = x.Attribute("col2").Value,
											col3 = x.Attribute("col3").Value
										 }  
							    ) ;
	  
	  var col3eq101 = second_list.Where(i => i.col3 == "101");
	  
	  first_list.Dump();
	  second_list.Dump();
	  col3eq101.Dump();
	   
}
...
Рейтинг: 0 / 0
03.09.2013, 11:01
    #38385103
Saules
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
беда в том, что на строках
Код: vbnet
1.
   mainBox.ValueMember = "ID"


и
Код: vbnet
1.
  subBox.ValueMember = "ID"


вылетает ошибка:
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Cannot bind to the new value member.
Parameter name: value
...
Рейтинг: 0 / 0
03.09.2013, 11:35
    #38385171
buser
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
на кой вот это mainBox.Items.Add
при условии mainBox.DataSource = GetMainItems()
...
Рейтинг: 0 / 0
03.09.2013, 11:37
    #38385174
buser
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
и вообще... на бейсике более многословно получается... но коль пользуете линк... посмотрите на мой пример... и уберите все это многословие нах...
...
Рейтинг: 0 / 0
03.09.2013, 11:57
    #38385210
Saules
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VBA + XML выборка данных
не уверен, что это правильно , но работает без ошибок так:
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        mainBox.DataSource = GetMainItems()
        ''  mainBox.DisplayMember = "Name"
        ''  mainBox.ValueMember = "ID"

    End Sub


и
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
 Private Sub mainBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mainBox.SelectedIndexChanged

        subBox.DataSource = Nothing
        subBox.Items.Clear()
        subBox.DataSource = GetSubItems()

    End Sub
...
Рейтинг: 0 / 0
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / VBA + XML выборка данных / 9 сообщений из 9, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]