将ListBox值存储到变量中

时间:2017-06-05 04:33:41

标签: excel vba excel-vba excel-2010

我正在尝试将选定的列表框值存储为变量。当我调试.List(r, 9)时。 "10"返回RowSelect这是正确的但""返回"10"这是不正确的。它应该返回Dim PendClick As Boolean Dim RrkBoxChg As Long Dim r As Long Dim m As Long Dim wsh As Worksheet Dim RowSelect As String Private Sub ListBox2_Click() With Me.ListBox2 If .ListIndex = -1 Then ElseIf .ListIndex >= 0 Then r = .ListIndex If PendClick = True Then Me.TextBox_Remarks = .List(r, 5) RowSelect = .List(r, 9) ElseIf PendClick = False Then Me.TextBox_Remarks = .List(r, 6) RowSelect = .List(r, 9) End If End If End With End Sub Private Sub TextBox_Remarks_Change() r = Me.ListBox2.ListIndex If PendClick = True Then Me.ListBox2.List(r, 5) = Me.TextBox_Remarks Worksheets("ToolData").Cells(RowSelect, 12) = Me.TextBox_Remarks ElseIf PendClick = False Then Me.ListBox2.List(r, 6) = Me.TextBox_Remarks Worksheets("ToolData").Cells(RowSelect, 12) = Me.TextBox_Remarks End If End Sub 。为什么变量没有返回正确的字符串?

这是我到目前为止所做的。

public class ProfileD extends Fragment {

TextView tv_named, tv_genderd, tv_cfd, tv_aged, tv_biod, tv_statusd;
ImageView imageView_dp;

public ProfileD() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_profile_d, container, false);

    tv_named = (TextView)rootView.findViewById(R.id.tv_named);
    tv_genderd = (TextView)rootView.findViewById(R.id.tv_genderd);
    tv_cfd= (TextView)rootView.findViewById(R.id.tv_cfd);
    tv_aged = (TextView)rootView.findViewById(R.id.tv_aged);
    tv_biod = (TextView)rootView.findViewById(R.id.tv_biod);

    tv_statusd = (TextView) rootView.findViewById(R.id.tv_statusd);

    imageView_dp = (ImageView)rootView.findViewById(R.id.imageView_dp);
    setHasOptionsMenu(true);

    return rootView;
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    super.onCreateOptionsMenu(menu, inflater);

    getActivity().getMenuInflater().inflate(R.menu.profile_menu, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.edit_profile) {

        Intent intent = new Intent(getContext(),PersonalDetails.class);
        intent.putExtra("Edit",1);
        startActivity(intent);

        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onResume() {
    super.onResume();

    AppCompatActivity appCompatActivity = (AppCompatActivity)getActivity();
    ActionBar actionBar = appCompatActivity.getSupportActionBar();
    actionBar.setTitle("Profile");
}
}

1 个答案:

答案 0 :(得分:0)

所以我发现了这个问题。 Me.TextBox_Remarks = .List(r, 5)触发了TextBox_Remarks_Change()事件。然后由于变量RowSelect = ""而错误输出。我只是简单地转换Me.TextBox_Remarks = .List(r, 5)RowSelect = .List(r, 9)的位置,以便事件顺序正确。这是纠正。

     If PendClick = True Then
        RowSelect = .List(r, 9)
        Me.TextBox_Remarks = .List(r, 5)
     ElseIf PendClick = False Then
        RowSelect = .List(r, 9)
        Me.TextBox_Remarks = .List(r, 6)
    End If